curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y npm
这是官方指示:
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
完成这个步骤后,运行nodejs --version
会返回v4.2.6
。
由于我使用了setup_6.x
,我本以为安装的版本应该以6
开头。
我想也许setup_6.x
应该是setup_6.2.1
,但是那个页面返回了404错误,请参见:
https://deb.nodesource.com/setup_6.x(页面存在)
https://deb.nodesource.com/setup_6.2.1(返回404错误)
如何在Ubuntu 16.04上安装最新稳定版的Node.js?
编辑:
以下是运行sudo apt-get install -y nodejs
后的结果:
sudo apt-get install -y nodejs
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
gyp libboost-python1.58.0 libjs-inherits libjs-node-uuid libjs-underscore
libssl-dev libssl-doc libuv1-dev linux-headers-4.4.0-18
linux-headers-4.4.0-18-generic linux-headers-4.4.0-21
linux-headers-4.4.0-21-generic linux-image-4.4.0-18-generic
linux-image-4.4.0-21-generic linux-image-extra-4.4.0-18-generic
linux-image-extra-4.4.0-21-generic linux-signed-image-4.4.0-18-generic
linux-signed-image-4.4.0-21-generic python-configobj python-pycurl
python-pyexiv2 python-pyexiv2-doc
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
nodejs
0 to upgrade, 1 to newly install, 0 to remove and 0 not to upgrade.
Need to get 0 B/3,162 kB of archives.
After this operation, 13.2 MB of additional disk space will be used.
Selecting previously unselected package nodejs.
(Reading database ... 329473 files and directories currently installed.)
Preparing to unpack .../nodejs_4.2.6~dfsg-1ubuntu4_amd64.deb ...
Unpacking nodejs (4.2.6~dfsg-1ubuntu4) ...
Processing triggers for doc-base (0.10.7) ...
Processing 1 added doc-base file...
Registering documents with scrollkeeper...
Processing triggers for man-db (2.7.5-1) ...
Setting up nodejs (4.2.6~dfsg-1ubuntu4) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode
编辑:
apt-cache policy nodejs
的结果如下:
apt-cache policy nodejs
nodejs:
Installed: 4.2.6~dfsg-1ubuntu4
Candidate: 4.2.6~dfsg-1ubuntu4
Version table:
*** 4.2.6~dfsg-1ubuntu4 500
500 http://au.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
100 /var/lib/dpkg/status
apt-cache policy nodejs
的输出副本包含在您的问题中作为编辑。 - Thomas Wardapt-cache
数据,以便我们可以查看您的计算机在存储库中存在什么,我们可能能够提供进一步的帮助。 - Thomas Wardsudo
权限的shell中并不是一个好主意... - pipenode v6.9.1
和npm 3.10.8
。此时的说明只需要执行sudo apt-get install nodejs
(在通过管道传输脚本后),你问题中的sudo apt-get install -y npm
这一行已经不再出现在官方说明中。 - Marcus Junius Brutus