轉 - ubuntu 安裝node.js 與 npm

原文連接爲: https://blog.csdn.net/wangtaoking1/article/details/78005038node

 

這篇文章介紹如何在ubuntu環境下安裝node環境。python

我使用的系統是ubuntu 16.04,不過在其餘版本的系統中應該也適用。npm

安裝python-software-properties

首先須要安裝依賴包python-software-properties。ubuntu

$ sudo apt-get install python-software-properties

 

添加PPA

網站deb.nodesource.com維護了nodejs的各版本安裝包的PPA,咱們能夠從該網站上下載執行導入。windows

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

 

若是提示沒有安裝curl,須要先安裝curl。 
當前6.x版本爲比較穩定的版本,咱們能夠根據本身的須要選擇安裝不一樣的版本。bash

安裝nodejs和npm

接下來安裝nodejs,安裝完成以後npm也自動安裝好了。網絡

$ sudo apt-get install nodejs

 

安裝完成以後咱們查看一下nodejs和npm的版本。curl

$ node -v
v8.5.0
$ npm -v
v5.3.0

 

配置npm倉庫

由於國內的網絡環境,直接從npm官方源安裝軟件包速度會比較慢,甚至致使安裝不成功。 
咱們能夠安裝nrm工具,用於管理軟件源。工具

$ npm install -g nrm

 

安裝完成以後,列出可用的軟件源網站

$ nrm ls
* npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
  taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/

 

 

在國內,咱們能夠使用taobao的源,速度還相對不錯。

$ nrm use taobao

Registry has been set to: https://registry.npm.taobao.org/

 

配置代理

另外,若是在特定網絡環境下須要配置代理的話,能夠使用以下命令配置。

$ npm config set proxy http://127.0.0.1:3128
$ npm config set http-proxy http://127.0.0.1:3128
$ npm config set https-proxy https://127.0.0.1:3128

 

 

配置代理的方法在windows環境下也是適用的。

相關文章
相關標籤/搜索