Ubuntu安装源安装nodejs

前端之家收集整理的这篇文章主要介绍了Ubuntu安装源安装nodejs前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文演示Ubuntu安装nodejs,当前(2017年11月13日)最新稳定版本为9.x。

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

下面是安装具体步骤演示代码。(以实际代码运行结果为准,仅供参考)

  1. root@minmin-VirtualBox:~# curl -sL https://deb.nodesource.com/setup | sudo bash -
  2. #root账号去掉sudo
  3. root@minmin-VirtualBox:~# curl -sL https://deb.nodesource.com/setup | bash -
  4. ================================================================================
  5. ================================================================================
  6.  
  7. SCRIPT DEPRECATION WARNING
  8.  
  9. This script,located at https://deb.nodesource.com/setup,used to
  10. install Node.js v0.10,is being deprecated and will eventually be made
  11. inactive.
  12.  
  13. You should use the script that corresponds to the version of Node.js you
  14. wish to install. e.g.
  15.  
  16. * https://deb.nodesource.com/setup_4.x — Node.js v4 LTS "Argon" (recommended)
  17. * https://deb.nodesource.com/setup_6.x — Node.js v6 Current
  18.  
  19. Please see https://github.com/nodejs/LTS/ for details about which version
  20. may be appropriate for you.
  21.  
  22. The NodeSource Node.js Linux distributions GitHub repository contains
  23. information about which versions of Node.js and which Linux distributions
  24. are supported and how to use the install scripts.
  25. https://github.com/nodesource/distributions
  26.  
  27. ================================================================================
  28. ================================================================================
  29.  
  30. Continuing in 10 seconds (press Ctrl-C to abort) ...
  31.  
  32.  
  33. ## Installing the NodeSource Node.js v0.10 repo...
  34.  
  35.  
  36. ## Populating apt-get cache...
  37.  
  38. + apt-get update
  39. 命中:1 http://cn.archive.ubuntu.com/ubuntu xenial InRelease
  40. 获取:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
  41. 获取:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
  42. 获取:4 http://cn.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
  43. 获取:5 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [653 kB]
  44. 命中:6 http://ppa.launchpad.net/elementary-os/stable/ubuntu xenial InRelease
  45. 获取:7 http://packages.elementary.io/appcenter xenial InRelease [5,894 B]
  46. 获取:8 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main i386 Packages [618 kB]
  47. 命中:9 http://ppa.launchpad.net/elementary-os/os-patches/ubuntu xenial InRelease
  48. 获取:10 http://apt.postgresql.org/pub/repos/apt xenial-pgdg InRelease [46.4 kB]
  49. 获取:11 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main amd64 Packages [72.5 kB]
  50. 获取:12 http://security.ubuntu.com/ubuntu xenial-security/main amd64 DEP-11 Metadata [60.3 kB]
  51. 获取:13 http://packages.elementary.io/appcenter xenial/main amd64 Packages [39.1 kB]
  52. 获取:14 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main i386 Packages [70.6 kB]
  53. 获取:15 http://security.ubuntu.com/ubuntu xenial-security/main DEP-11 64x64 Icons [67.1 kB]
  54. 获取:16 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [274 kB]
  55. 获取:17 http://packages.elementary.io/appcenter xenial/main amd64 DEP-11 Metadata [31.4 kB]
  56. 获取:18 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 DEP-11 Metadata [307 kB]
  57. 获取:19 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 DEP-11 Metadata [51.4 kB]
  58. 获取:20 http://packages.elementary.io/appcenter xenial/main DEP-11 64x64 Icons [171 kB]
  59. 获取:21 http://security.ubuntu.com/ubuntu xenial-security/universe DEP-11 64x64 Icons [85.1 kB]
  60. 获取:22 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main DEP-11 64x64 Icons [220 kB]
  61. 获取:23 http://cn.archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [8,064 B]
  62. 获取:24 http://cn.archive.ubuntu.com/ubuntu xenial-updates/restricted i386 Packages [8,084 B]
  63. 获取:25 http://cn.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [544 kB]
  64. 获取:26 http://cn.archive.ubuntu.com/ubuntu xenial-updates/universe i386 Packages [518 kB]
  65. 获取:27 http://cn.archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [221 kB]
  66. 获取:28 http://cn.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 DEP-11 Metadata [174 kB]
  67. 获取:29 http://cn.archive.ubuntu.com/ubuntu xenial-updates/universe DEP-11 64x64 Icons [245 kB]
  68. 获取:30 http://cn.archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [16.2 kB]
  69. 获取:31 http://cn.archive.ubuntu.com/ubuntu xenial-updates/multiverse i386 Packages [15.3 kB]
  70. 获取:32 http://cn.archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 DEP-11 Metadata [5,888 B]
  71. 获取:33 http://cn.archive.ubuntu.com/ubuntu xenial-backports/main amd64 DEP-11 Metadata [3,324 B]
  72. 获取:34 http://cn.archive.ubuntu.com/ubuntu xenial-backports/universe amd64 DEP-11 Metadata [4,588 B]
  73. 已下载 4,841 kB,耗时 19 (246 kB/s)
  74. 正在读取软件包列表... 完成
  75.  
  76. ## You seem to be using elementaryOS version loki.
  77. ## This maps to Ubuntu "xenial"... Adjusting for you...
  78.  
  79. ## Confirming "xenial" is supported...
  80.  
  81. + curl -sLf -o /dev/null 'https://deb.nodesource.com/node_0.10/dists/xenial/Release'
  82.  
  83. ## Adding the NodeSource signing key to your keyring...
  84.  
  85. + curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
  86. OK
  87.  
  88. ## Creating apt sources list file for the NodeSource Node.js v0.10 repo...
  89.  
  90. + echo 'deb https://deb.nodesource.com/node_0.10 xenial main' > /etc/apt/sources.list.d/nodesource.list
  91. + echo 'deb-src https://deb.nodesource.com/node_0.10 xenial main' >> /etc/apt/sources.list.d/nodesource.list
  92.  
  93. ## Running `apt-get update` for you...
  94.  
  95. + apt-get update
  96. 命中:1 http://cn.archive.ubuntu.com/ubuntu xenial InRelease
  97. 命中:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates InRelease
  98. 命中:3 http://cn.archive.ubuntu.com/ubuntu xenial-backports InRelease
  99. 命中:4 http://security.ubuntu.com/ubuntu xenial-security InRelease
  100. 命中:5 http://apt.postgresql.org/pub/repos/apt xenial-pgdg InRelease
  101. 命中:6 http://packages.elementary.io/appcenter xenial InRelease
  102. 命中:7 http://ppa.launchpad.net/elementary-os/stable/ubuntu xenial InRelease
  103. 获取:8 https://deb.nodesource.com/node_0.10 xenial InRelease [3,899 B]
  104. 获取:9 https://deb.nodesource.com/node_0.10 xenial/main Sources [682 B]
  105. 获取:10 https://deb.nodesource.com/node_0.10 xenial/main amd64 Packages [932 B]
  106. 获取:11 https://deb.nodesource.com/node_0.10 xenial/main i386 Packages [932 B]
  107. 命中:12 http://ppa.launchpad.net/elementary-os/os-patches/ubuntu xenial InRelease
  108. 已下载 6,445 B,耗时 4 (1,414 B/s)
  109. 正在读取软件包列表... 完成
  110.  
  111. ================================================================================
  112. ================================================================================
  113.  
  114. NODE.JS v0.10 DEPRECATION WARNING
  115.  
  116. Node.js v0.10 will cease to be actively supported in October 2016.
  117.  
  118. This means you will not continue to receive security or critical stability
  119. updates for this version of Node.js beyond that time.
  120.  
  121. You should begin migration to a newer version of Node.js as soon as
  122. possible. Use the installation script that corresponds to the version of
  123. Node.js you wish to install. e.g.
  124.  
  125. * https://deb.nodesource.com/setup_4.x — Node.js v4 LTS "Argon" (recommended)
  126. * https://deb.nodesource.com/setup_6.x — Node.js v6 Current
  127.  
  128. Please see https://github.com/nodejs/LTS/ for details about which version
  129. may be appropriate for you.
  130.  
  131. The NodeSource Node.js Linux distributions GitHub repository contains
  132. information about which versions of Node.js and which Linux distributions
  133. are supported and how to use the install scripts.
  134. https://github.com/nodesource/distributions
  135.  
  136. ================================================================================
  137. ================================================================================
  138.  
  139. Continuing in 5 seconds ...
  140.  
  141.  
  142. ## Run `apt-get install nodejs` (as root) to install Node.js v0.10 and npm

切换到root 账号或使用root账户权限。

  1. root@minmin-VirtualBox:~# sudo -i
  2. #输入root用户密码
  3. root@minmin-VirtualBox:~# apt update
  4. root@minmin-VirtualBox:~# apt install nodejs nodejs-dev nodejs-dbg debhelper

完成安装后,就可以使用npm,检查版本信息。

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

使用淘宝安装源替换系统默认npm,等待安装进度完成。

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

演示安装http-server。

  1. root@minmin-VirtualBox:~# cnpm install -g http-server
  2. Downloading http-server to /usr/lib/node_modules/http-server_tmp
  3. [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":{}})
  4. headers: {}
  5. Copying /usr/lib/node_modules/http-server_tmp/_http-server@0.10.0@http-server to /usr/lib/node_modules/http-server
  6. Installing http-server's dependencies to /usr/lib/node_modules/http-server/node_modules
  7. [1/8] opener@~1.4.0 installed at node_modules/_opener@1.4.3@opener
  8. [2/8] colors@1.0.3 installed at node_modules/_colors@1.0.3@colors
  9. [3/8] optimist@0.6.x installed at node_modules/_optimist@0.6.1@optimist
  10. [4/8] ecstatic@^2.0.0 installed at node_modules/_ecstatic@2.2.1@ecstatic
  11. [npminstall:get] retry GET http://registry.npm.taobao.org/corser/download/corser-2.0.1.tgz after 100ms,GET https://cdn.npm.taobao.org/corser/-/corser-2.0.1.tgz -2 (connected: false,agent status: {"createSocketCount":9,"closeSocketCount":6,"timeoutSocketCount":4,"requestCount":11,"sockets":{"cdn.npm.taobao.org:443:::::::true::":3},"requests":{}})
  12. headers: {}
  13. [npminstall:get] retry GET http://registry.npm.taobao.org/http-proxy/download/http-proxy-1.16.2.tgz after 100ms,GET https://cdn.npm.taobao.org/http-proxy/-/http-proxy-1.16.2.tgz -2 (connected: false,"closeSocketCount":7,"sockets":{"cdn.npm.taobao.org:443:::::::true::":2},"requests":{}})
  14. headers: {}
  15. [npminstall:get] retry GET http://registry.npm.taobao.org/union/download/union-0.4.6.tgz after 100ms,GET https://cdn.npm.taobao.org/union/-/union-0.4.6.tgz -2 (connected: false,"closeSocketCount":8,"sockets":{"cdn.npm.taobao.org:443:::::::true::":1},"requests":{}})
  16. headers: {}
  17. [npminstall:get] retry GET http://registry.npm.taobao.org/portfinder/download/portfinder-1.0.13.tgz after 100ms,GET https://cdn.npm.taobao.org/portfinder/-/portfinder-1.0.13.tgz -2 (connected: false,"closeSocketCount":9,"requests":{}})
  18. headers: {}
  19. [5/8] union@~0.4.3 installed at node_modules/_union@0.4.6@union
  20. [npminstall:get] retry GET http://registry.npm.taobao.org/corser/download/corser-2.0.1.tgz after 200ms,retry left 3,agent status: {"createSocketCount":14,"closeSocketCount":12,"timeoutSocketCount":6,"requestCount":17,"requests":{}})
  21. headers: {}
  22. [npminstall:get] retry GET http://registry.npm.taobao.org/http-proxy/download/http-proxy-1.16.2.tgz after 200ms,"closeSocketCount":13,"requests":{}})
  23. headers: {}
  24. [npminstall:get] retry GET http://registry.npm.taobao.org/mkdirp/download/mkdirp-0.5.1.tgz after 100ms,GET https://cdn.npm.taobao.org/mkdirp/-/mkdirp-0.5.1.tgz -2 (connected: false,agent status: {"createSocketCount":16,"closeSocketCount":14,"requests":{}})
  25. headers: {}
  26. [6/8] corser@~2.0.0 installed at node_modules/_corser@2.0.1@corser
  27. [7/8] portfinder@^1.0.13 installed at node_modules/_portfinder@1.0.13@portfinder
  28. [8/8] http-proxy@^1.8.1 installed at node_modules/_http-proxy@1.16.2@http-proxy
  29. All packages installed (22 packages installed from npm registry,used 2m,speed 8.77kB/s,json 20(45.15kB),tarball 1020.36kB)
  30. [http-server@0.10.0] link /usr/bin/http-server@ -> /usr/lib/node_modules/http-server/bin/http-server
  31. [http-server@0.10.0] link /usr/bin/hs@ -> /usr/lib/node_modules/http-server/bin/http-server
  32. root@minmin-VirtualBox:~#
  33. root@minmin-VirtualBox:~# http-server &
  34. [3] 3522
  35. root@minmin-VirtualBox:~# Starting up http-server,serving ./
  36. Available on:
  37. http://127.0.0.1:8080
  38. http://10.1.1.1:8080
  39. Hit CTRL-C to stop the server
  40. root@minmin-VirtualBox:~#

参考链接

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

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

猜你在找的Ubuntu相关文章