1. ubuntu软件仓库中自带的nodejs版本过低
$ apt-cache policy nodejs
nodejs:
Installed: (none)
Candidate: 4.2.6~dfsg-1ubuntu4.2
Version table:
4.2.6~dfsg-1ubuntu4.2 500
500 http://mirrors.aliyun.com/ubuntu xenial-updates/universe amd64 Packages
500 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages
4.2.6~dfsg-1ubuntu4 500
500 http://mirrors.aliyun.com/ubuntu xenial/universe amd64 Packages
  1. 要安装高版本需要使用新的镜像源

    但国内访问deb.nodesource.com会出现连接超时,需要设置代理

    测试结果如下:
$ curl -sL -v https://deb.nodesource.com/setup_8.x
* Trying 13.35.8.34...
* Connected to deb.nodesource.com (13.35.8.34) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 592 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* gnutls_handshake() failed: The TLS connection was non-properly terminated.
* Closing connection 0

Step1> 设置代理

以socks5代理为例:

$ export http_proxy=socks5://127.0.0.1:1080
$ export HTTPS_PROXY=socks5://127.0.0.1:1080

Step2> 使用脚本进行安装:

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

安装记录

## Confirming "xenial" is supported...

+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_8.x/dists/xenial/Release'

## Adding the NodeSource signing key to your keyring...

+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
OK ## Creating apt sources list file for the NodeSource Node.js 8.x LTS Carbon repo... + echo 'deb https://deb.nodesource.com/node_8.x xenial main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src https://deb.nodesource.com/node_8.x xenial main' >> /etc/apt/sources.list.d/nodesource.list ## Running `apt-get update` for you... + apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu xenial InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu xenial-updates InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu xenial-backports InRelease
Hit:4 http://mirrors.aliyun.com/ubuntu xenial-security InRelease
Hit:5 http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial InRelease
Get:6 https://deb.nodesource.com/node_8.x xenial InRelease [4,646 B]
Get:7 https://deb.nodesource.com/node_8.x xenial/main Sources [761 B]
Get:8 https://deb.nodesource.com/node_8.x xenial/main amd64 Packages [1,006 B]
Get:9 https://deb.nodesource.com/node_8.x xenial/main i386 Packages [1,004 B]
Fetched 7,417 B in 1s (5,551 B/s)
Reading package lists... Done ## Run `sudo apt-get install -y nodejs` to install Node.js 8.x LTS Carbon and npm
## You may also need development tools to build native addons:
sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn

如果不想使用脚本,也可以选择手动安装,过程如下:

$ sudo apt-get install apt-transport-https

# 使用代理下载nodesource.gpg.key
$ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
OK # 使用清华镜像源
$ sudo bash -c "echo \"deb https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_8.x xenial main\" > /etc/apt/sources.list.d/nodesource.list"
$ sudo bash -c "echo \"deb-src https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_8.x/ xenial main\" >> /etc/apt/sources.list.d/nodesource.list" $ cat /etc/apt/sources.list.d/nodesource.list
deb https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_8.x xenial main
deb-src https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_8.x/ xenial main $ sudo apt-get update
$ sudo apt-get install nodejs

nodejs安装核心步骤

key相关操作

$ apt-key list
...
pub 4096R/68576280 2014-06-13
uid NodeSource <gpg@nodesource.com>
sub 4096R/AA01DA2C 2014-06-13
...
$sudo apt-key del 68576280
$apt-key list | grep node

参考:

最新文章

  1. nodejs利用ajax实现网页无刷新上传图片
  2. Python模块之常用模块,反射以及正则表达式
  3. Android实现KSOAP2访问WebService
  4. springMVC get请求及其请求地址写法
  5. Linux - How To Set Up an NFS Mount on CentOS 6
  6. VC/MFC 工具栏上动态添加组合框等控件的方法
  7. Socket 传送文件
  8. 内置open()函数对外部文件的操作
  9. NGUI_slider
  10. Java中判断对象是否为空的方法
  11. 【scarletthln 关于算法的一点总结】
  12. I2C地址问题
  13. 关于const修饰指针
  14. fastreport报表中出现十字线
  15. Jexus 安装asp.net mvc EF 项目引发的错误总
  16. PAT甲题题解-1119. Pre- and Post-order Traversals (30)-(根据前序、后序求中序)
  17. CCCC 成都信息工程大学游记
  18. springboot+jps+druid项目搭建
  19. Elasticsearch Java API—多条件查询(must)
  20. linux vi编辑器中,如何通过快捷键上下翻页?

热门文章

  1. Docker部署Django项目+Nginx+Fluend日志收集 和redis、memcached、RabbitMQ、Celery
  2. WindowsForms 调用API
  3. Forth 词典和词汇
  4. centos重置密码
  5. python项目运行环境安装小结
  6. jq demo 轮播图,图片可调用,向上,自动+鼠标点击切换
  7. 2.6 利用FTP上传所有文件
  8. 网络知识梳理--OSI七层网络与TCP/IP五层网络架构及二层/三层网络(转)
  9. keras 实现人工神经网络
  10. Problem A: 平面上的点和线——Point类、Line类 (I)