curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - 安装失败

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaoleizhanghahaha/article/details/83715721
  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 <[email protected]>
sub   4096R/AA01DA2C 2014-06-13
...
$sudo apt-key del 68576280
$apt-key list | grep node

参考:

  • https://nodejs.org/zh-cn/download/package-manager/
  • https://mirror.tuna.tsinghua.edu.cn/help/nodesource/

猜你喜欢

转载自blog.csdn.net/xiaoleizhanghahaha/article/details/83715721
sl
今日推荐