原文连接为: https://blog.csdn.net/wangtaoking1/article/details/78005038node
这篇文章介绍如何在ubuntu环境下安装node环境。python
我使用的系统是ubuntu 16.04,不过在其余版本的系统中应该也适用。npm
首先须要安装依赖包python-software-properties。ubuntu
$ sudo apt-get install python-software-properties
网站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也自动安装好了。网络
$ sudo apt-get install nodejs
安装完成以后咱们查看一下nodejs和npm的版本。curl
$ node -v v8.5.0 $ npm -v v5.3.0
由于国内的网络环境,直接从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环境下也是适用的。