Ubuntu安裝源安裝nodejs

本文演示Ubuntu安裝nodejs,當前(2017年11月13日)最新穩定版本爲9.x。html

#安裝nodejs9.x
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -

下面是安裝具體步驟演示代碼。(以實際代碼運行結果爲準,僅供參考)node

root@minmin-VirtualBox:~# curl -sL https://deb.nodesource.com/setup | sudo bash -
#root帳號去掉sudo
root@minmin-VirtualBox:~# curl -sL https://deb.nodesource.com/setup | bash -    
================================================================================
================================================================================

                           SCRIPT DEPRECATION WARNING

  This script, located at https://deb.nodesource.com/setup, used to
  install Node.js v0.10, is being deprecated and will eventually be made
  inactive.

  You should use the script that corresponds to the version of Node.js you
  wish to install. e.g.

   * https://deb.nodesource.com/setup_4.x — Node.js v4 LTS "Argon" (recommended)
   * https://deb.nodesource.com/setup_6.x — Node.js v6 Current

  Please see https://github.com/nodejs/LTS/ for details about which version
  may be appropriate for you.

  The NodeSource Node.js Linux distributions GitHub repository contains
  information about which versions of Node.js and which Linux distributions
  are supported and how to use the install scripts.
    https://github.com/nodesource/distributions

================================================================================
================================================================================

Continuing in 10 seconds (press Ctrl-C to abort) ...


## Installing the NodeSource Node.js v0.10 repo...


## Populating apt-get cache...

+ apt-get update
命中:1 http://cn.archive.ubuntu.com/ubuntu xenial InRelease
獲取:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
獲取:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
獲取:4 http://cn.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
獲取:5 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [653 kB]
命中:6 http://ppa.launchpad.net/elementary-os/stable/ubuntu xenial InRelease
獲取:7 http://packages.elementary.io/appcenter xenial InRelease [5,894 B]
獲取:8 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main i386 Packages [618 kB]
命中:9 http://ppa.launchpad.net/elementary-os/os-patches/ubuntu xenial InRelease
獲取:10 http://apt.postgresql.org/pub/repos/apt xenial-pgdg InRelease [46.4 kB]
獲取:11 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main amd64 Packages [72.5 kB]
獲取:12 http://security.ubuntu.com/ubuntu xenial-security/main amd64 DEP-11 Metadata [60.3 kB]
獲取:13 http://packages.elementary.io/appcenter xenial/main amd64 Packages [39.1 kB]
獲取:14 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main i386 Packages [70.6 kB]
獲取:15 http://security.ubuntu.com/ubuntu xenial-security/main DEP-11 64x64 Icons [67.1 kB]
獲取:16 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [274 kB]
獲取:17 http://packages.elementary.io/appcenter xenial/main amd64 DEP-11 Metadata [31.4 kB]
獲取:18 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 DEP-11 Metadata [307 kB]
獲取:19 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 DEP-11 Metadata [51.4 kB]
獲取:20 http://packages.elementary.io/appcenter xenial/main DEP-11 64x64 Icons [171 kB]
獲取:21 http://security.ubuntu.com/ubuntu xenial-security/universe DEP-11 64x64 Icons [85.1 kB]
獲取:22 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main DEP-11 64x64 Icons [220 kB]
獲取:23 http://cn.archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [8,064 B]
獲取:24 http://cn.archive.ubuntu.com/ubuntu xenial-updates/restricted i386 Packages [8,084 B]
獲取:25 http://cn.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [544 kB]
獲取:26 http://cn.archive.ubuntu.com/ubuntu xenial-updates/universe i386 Packages [518 kB]
獲取:27 http://cn.archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [221 kB]
獲取:28 http://cn.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 DEP-11 Metadata [174 kB]
獲取:29 http://cn.archive.ubuntu.com/ubuntu xenial-updates/universe DEP-11 64x64 Icons [245 kB]
獲取:30 http://cn.archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [16.2 kB]
獲取:31 http://cn.archive.ubuntu.com/ubuntu xenial-updates/multiverse i386 Packages [15.3 kB]
獲取:32 http://cn.archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 DEP-11 Metadata [5,888 B]
獲取:33 http://cn.archive.ubuntu.com/ubuntu xenial-backports/main amd64 DEP-11 Metadata [3,324 B]
獲取:34 http://cn.archive.ubuntu.com/ubuntu xenial-backports/universe amd64 DEP-11 Metadata [4,588 B]
已下載 4,841 kB,耗時 19秒 (246 kB/s)
正在讀取軟件包列表... 完成

## You seem to be using elementaryOS version loki.
## This maps to Ubuntu "xenial"... Adjusting for you...

## Confirming "xenial" is supported...

+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_0.10/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 v0.10 repo...

+ echo 'deb https://deb.nodesource.com/node_0.10 xenial main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src https://deb.nodesource.com/node_0.10 xenial main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
命中:1 http://cn.archive.ubuntu.com/ubuntu xenial InRelease
命中:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates InRelease
命中:3 http://cn.archive.ubuntu.com/ubuntu xenial-backports InRelease
命中:4 http://security.ubuntu.com/ubuntu xenial-security InRelease
命中:5 http://apt.postgresql.org/pub/repos/apt xenial-pgdg InRelease
命中:6 http://packages.elementary.io/appcenter xenial InRelease
命中:7 http://ppa.launchpad.net/elementary-os/stable/ubuntu xenial InRelease
獲取:8 https://deb.nodesource.com/node_0.10 xenial InRelease [3,899 B]
獲取:9 https://deb.nodesource.com/node_0.10 xenial/main Sources [682 B]
獲取:10 https://deb.nodesource.com/node_0.10 xenial/main amd64 Packages [932 B]
獲取:11 https://deb.nodesource.com/node_0.10 xenial/main i386 Packages [932 B]
命中:12 http://ppa.launchpad.net/elementary-os/os-patches/ubuntu xenial InRelease
已下載 6,445 B,耗時 4秒 (1,414 B/s)
正在讀取軟件包列表... 完成

================================================================================
================================================================================

                       NODE.JS v0.10 DEPRECATION WARNING

  Node.js v0.10 will cease to be actively supported in October 2016.

  This means you will not continue to receive security or critical stability
  updates for this version of Node.js beyond that time.

  You should begin migration to a newer version of Node.js as soon as
  possible. Use the installation script that corresponds to the version of
  Node.js you wish to install. e.g.

   * https://deb.nodesource.com/setup_4.x — Node.js v4 LTS "Argon" (recommended)
   * https://deb.nodesource.com/setup_6.x — Node.js v6 Current

  Please see https://github.com/nodejs/LTS/ for details about which version
  may be appropriate for you.

  The NodeSource Node.js Linux distributions GitHub repository contains
  information about which versions of Node.js and which Linux distributions
  are supported and how to use the install scripts.
    https://github.com/nodesource/distributions

================================================================================
================================================================================

Continuing in 5 seconds ...


## Run `apt-get install nodejs` (as root) to install Node.js v0.10 and npm

切換到root 帳號或使用root帳戶權限。git

root@minmin-VirtualBox:~# sudo -i
#輸入root用戶密碼
root@minmin-VirtualBox:~# apt update
root@minmin-VirtualBox:~# apt install nodejs nodejs-dev nodejs-dbg debhelper

完成安裝後,就可使用npm,檢查版本信息。github

root@minmin-VirtualBox:~# nodejs -v
v9.1.0

使用淘寶安裝源替換系統默認npm,等待安裝進度完成。sql

root@minmin-VirtualBox:~# npm install -g cnpm --registry=https://registry.npm.taobao.org
[            ......] - extract:balanced-match: sill pacote balanced-match@http://registry.npm.taobao.org/balanced-match/download/balanced-matc
/usr/bin/cnpm -> /usr/lib/node_modules/cnpm/bin/cnpm
+ cnpm@5.1.1
added 692 packages in 1202.934s

演示安裝http-server。npm

root@minmin-VirtualBox:~# cnpm install -g http-server
Downloading http-server to /usr/lib/node_modules/http-server_tmp
[npminstall:get] retry GET http://registry.npm.taobao.org/http-server/download/http-server-0.10.0.tgz after 100ms, retry left 4, error: ConnectionTimeoutError: Connect timeout for 60000ms, GET https://cdn.npm.taobao.org/http-server/-/http-server-0.10.0.tgz -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":1,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{},"requests":{}})
headers: {}
Copying /usr/lib/node_modules/http-server_tmp/_http-server@0.10.0@http-server to /usr/lib/node_modules/http-server
Installing http-server's dependencies to /usr/lib/node_modules/http-server/node_modules
[1/8] opener@~1.4.0 installed at node_modules/_opener@1.4.3@opener
[2/8] colors@1.0.3 installed at node_modules/_colors@1.0.3@colors
[3/8] optimist@0.6.x installed at node_modules/_optimist@0.6.1@optimist
[4/8] ecstatic@^2.0.0 installed at node_modules/_ecstatic@2.2.1@ecstatic
[npminstall:get] retry GET http://registry.npm.taobao.org/corser/download/corser-2.0.1.tgz after 100ms, retry left 4, error: ConnectionTimeoutError: Connect timeout for 60000ms, GET https://cdn.npm.taobao.org/corser/-/corser-2.0.1.tgz -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":9,"createSocketErrorCount":0,"closeSocketCount":6,"errorSocketCount":0,"timeoutSocketCount":4,"requestCount":11,"freeSockets":{},"sockets":{"cdn.npm.taobao.org:443:::::::true::":3},"requests":{}})
headers: {}
[npminstall:get] retry GET http://registry.npm.taobao.org/http-proxy/download/http-proxy-1.16.2.tgz after 100ms, retry left 4, error: ConnectionTimeoutError: Connect timeout for 60000ms, GET https://cdn.npm.taobao.org/http-proxy/-/http-proxy-1.16.2.tgz -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":9,"createSocketErrorCount":0,"closeSocketCount":7,"errorSocketCount":0,"timeoutSocketCount":4,"requestCount":11,"freeSockets":{},"sockets":{"cdn.npm.taobao.org:443:::::::true::":2},"requests":{}})
headers: {}
[npminstall:get] retry GET http://registry.npm.taobao.org/union/download/union-0.4.6.tgz after 100ms, retry left 4, error: ConnectionTimeoutError: Connect timeout for 60000ms, GET https://cdn.npm.taobao.org/union/-/union-0.4.6.tgz -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":9,"createSocketErrorCount":0,"closeSocketCount":8,"errorSocketCount":0,"timeoutSocketCount":4,"requestCount":11,"freeSockets":{},"sockets":{"cdn.npm.taobao.org:443:::::::true::":1},"requests":{}})
headers: {}
[npminstall:get] retry GET http://registry.npm.taobao.org/portfinder/download/portfinder-1.0.13.tgz after 100ms, retry left 4, error: ConnectionTimeoutError: Connect timeout for 60000ms, GET https://cdn.npm.taobao.org/portfinder/-/portfinder-1.0.13.tgz -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":9,"createSocketErrorCount":0,"closeSocketCount":9,"errorSocketCount":0,"timeoutSocketCount":4,"requestCount":11,"freeSockets":{},"sockets":{},"requests":{}})
headers: {}
[5/8] union@~0.4.3 installed at node_modules/_union@0.4.6@union
[npminstall:get] retry GET http://registry.npm.taobao.org/corser/download/corser-2.0.1.tgz after 200ms, retry left 3, error: ConnectionTimeoutError: Connect timeout for 60000ms, GET https://cdn.npm.taobao.org/corser/-/corser-2.0.1.tgz -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":14,"createSocketErrorCount":0,"closeSocketCount":12,"errorSocketCount":0,"timeoutSocketCount":6,"requestCount":17,"freeSockets":{},"sockets":{"cdn.npm.taobao.org:443:::::::true::":2},"requests":{}})
headers: {}
[npminstall:get] retry GET http://registry.npm.taobao.org/http-proxy/download/http-proxy-1.16.2.tgz after 200ms, retry left 3, error: ConnectionTimeoutError: Connect timeout for 60000ms, GET https://cdn.npm.taobao.org/http-proxy/-/http-proxy-1.16.2.tgz -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":14,"createSocketErrorCount":0,"closeSocketCount":13,"errorSocketCount":0,"timeoutSocketCount":6,"requestCount":17,"freeSockets":{},"sockets":{"cdn.npm.taobao.org:443:::::::true::":1},"requests":{}})
headers: {}
[npminstall:get] retry GET http://registry.npm.taobao.org/mkdirp/download/mkdirp-0.5.1.tgz after 100ms, retry left 4, error: ConnectionTimeoutError: Connect timeout for 60000ms, GET https://cdn.npm.taobao.org/mkdirp/-/mkdirp-0.5.1.tgz -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":16,"createSocketErrorCount":0,"closeSocketCount":14,"errorSocketCount":0,"timeoutSocketCount":6,"requestCount":17,"freeSockets":{},"sockets":{"cdn.npm.taobao.org:443:::::::true::":2},"requests":{}})
headers: {}
[6/8] corser@~2.0.0 installed at node_modules/_corser@2.0.1@corser
[7/8] portfinder@^1.0.13 installed at node_modules/_portfinder@1.0.13@portfinder
[8/8] http-proxy@^1.8.1 installed at node_modules/_http-proxy@1.16.2@http-proxy
All packages installed (22 packages installed from npm registry, used 2m, speed 8.77kB/s, json 20(45.15kB), tarball 1020.36kB)
[http-server@0.10.0] link /usr/bin/http-server@ -> /usr/lib/node_modules/http-server/bin/http-server
[http-server@0.10.0] link /usr/bin/hs@ -> /usr/lib/node_modules/http-server/bin/http-server
root@minmin-VirtualBox:~#
root@minmin-VirtualBox:~# http-server &
[3] 3522
root@minmin-VirtualBox:~# Starting up http-server, serving ./
Available on:
  http://127.0.0.1:8080
  http://10.1.1.1:8080
Hit CTRL-C to stop the server
root@minmin-VirtualBox:~#

參考連接:json

https://mirror.tuna.tsinghua.edu.cn/help/nodesource/ubuntu

http://www.mamicode.com/info-detail-1802382.htmlbash

相關文章
相關標籤/搜索