我已经使用以下代码在 Ubuntu 上安装了 nodeJS
sudo apt-get install nodejs
Run Code Online (Sandbox Code Playgroud)
由于我是 ubuntu 的新用户,因此我也运行了此代码
sudo apt-get install npm
Run Code Online (Sandbox Code Playgroud)
现在当我输入
nodejs --version
Run Code Online (Sandbox Code Playgroud)
表明
v0.6.19
Run Code Online (Sandbox Code Playgroud)
我检查并看到最新的 nodeJS 版本是 0.10.26
如何将我的 nodeJS 版本更新为0.10.26
?
我试过
sudo apt-get install <packagename>
sudo apt-get install --only-upgrade <packagename>
Run Code Online (Sandbox Code Playgroud)
但没有运气。
小智 1502
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Run Code Online (Sandbox Code Playgroud)
要升级到最新版本(而不是当前稳定的)版本,您可以使用
sudo n latest
Run Code Online (Sandbox Code Playgroud)
修复路径:
sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/node
Run Code Online (Sandbox Code Playgroud)
撤销:
sudo n rm 6.0.0 # replace number with version of Node that was installed
sudo npm uninstall -g n
Run Code Online (Sandbox Code Playgroud)
您可能需要重新启动终端才能查看更新的节点版本。
day*_*oli 546
完整的安装说明已经由 Nodesource上传到这里。复制如下,供大家参考。更新到最新版本的说明相同。
如果您不喜欢,curl ... | sudo bash -
那么您可以按照手册说明进行操作,其中会告诉您如何将 Node.js 存储库添加到您/etc/apt/sources.list.d/
自己。
注意:如果您使用的是 Ubuntu Precise 或 Debian Wheezy,您可能需要阅读有关在旧发行版上运行 Node.js >= 6.x 的信息
Node.js 当前:
# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -fsSL https://deb.nodesource.com/setup_current.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v13.x:
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_13.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v12.x:
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v11.x:
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v10.x:
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v9.x:
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_9.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v8.x:
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v7.x:
注意:Debian Wheezy 和 Ubuntu Precise 软件包不适用于此版本。请参考在旧发行版上运行 Node.js >= 4.x
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_7.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v6.x:
注意:如果您使用的是 Ubuntu Precise 或 Debian Wheezy,您可能需要阅读有关在旧发行版上运行 Node.js >= 4.x 的信息。
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_6.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v5.x:
注意:如果您使用的是 Ubuntu Precise 或 Debian Wheezy,您可能需要阅读有关在旧发行版上运行 Node.js >= 4.x 的信息。
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_5.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v4.x:
注意:如果您使用的是 Ubuntu Precise 或 Debian Wheezy,您可能需要阅读有关在旧发行版上运行 Node.js >= 4.x 的信息。
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_4.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v0.12:
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_0.12 | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_0.12 | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
Node.js v0.10:
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_0.10 | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_0.10 | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
io.js v3.x :
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_iojs_3.x | sudo -E bash -
sudo apt-get install -y iojs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_iojs_3.x | bash -
apt-get install -y iojs
Run Code Online (Sandbox Code Playgroud)
io.js v2.x :
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_iojs_2.x | sudo -E bash -
sudo apt-get install -y iojs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_iojs_2.x | bash -
apt-get install -y iojs
Run Code Online (Sandbox Code Playgroud)
io.js v1.x :
注意:io.js 的这个分支没有积极维护,不推荐用于生产。
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_iojs_1.x | sudo -E bash -
sudo apt-get install -y iojs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_iojs_1.x | bash -
apt-get install -y iojs
Run Code Online (Sandbox Code Playgroud)
Min*_*ael 51
我还建议改用nvm,并删除已安装的版本以避免终端冲突
sudo apt purge nodejs npm
Run Code Online (Sandbox Code Playgroud)
然后安装 nvm 并使用它
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
Run Code Online (Sandbox Code Playgroud)
nvm install node
Run Code Online (Sandbox Code Playgroud)
应该下载并安装最新版本的节点。
稍后更新节点只需执行
nvm install node
nvm alias default node
Run Code Online (Sandbox Code Playgroud)
小智 27
此 PPA 已过时且不再维护;您应该考虑其他答案而不是这个答案。
您可以从 PPA 安装最新版本:
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
Run Code Online (Sandbox Code Playgroud)
小智 21
我使用 NVM 来处理我的 Node 版本。设置非常简单且易于使用。
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
Run Code Online (Sandbox Code Playgroud)
要全局安装 NVM,请使用以下 curl 命令而不是上面的命令(大概不要使用第二个命令,而是使用第三个命令)
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | NVM_DIR=/usr/local/nvm bash
Run Code Online (Sandbox Code Playgroud)
然后使用nvm install stable
(或插入版本号而不是stable
)来获取 Node.js 的最新/特定版本。使用nvm use stable
(或特定版本号)来使用该 Node 版本。使用nvm ls
看你所安装的节点版本和nvm uninstall stable
(或特定版本号)删除节点的特定版本。
如果您npm
因为卡在某个特定版本而难以更新到最新的稳定版本,npm
并且每次更新它都不起作用,那么您也可以使用此方法进行更新npm
。只要您安装了最新的稳定版本node
,npm
就会自动更新到最新的稳定版本。
Cir*_*郝海东 10
--lts
NVM 在以下位置被提及:https : //askubuntu.com/a/441527/52975但这里有一个更完整的使用示例,包括健全的--lts
版本,它安装最新的 Node 长期支持版本,这可能是您想要的如果您没有更具体的要求。
安装 NVM 和最新的 Node LTS 版本:
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh
source ~/.nvm/nvm.sh
nvm install --lts
nvm use --lts
npm --version
Run Code Online (Sandbox Code Playgroud)
现在用一个虚拟包测试一下:
npm install --global vaca
vaca
Run Code Online (Sandbox Code Playgroud)
由于必须为每个新 shell 进行采购,因此安装脚本黑客会在.barshrc
. 这有效,但我更喜欢删除自动添加的并添加我自己的:
f="$HOME/.nvm/nvm.sh"
if [ -r "$f" ]; then
. "$f" &>'/dev/null'
nvm use --lts &>'/dev/null'
fi
Run Code Online (Sandbox Code Playgroud)
好处:
允许您使用多个版本的 Node 而无需 sudo
类似于 Ruby RVM 和 Python Virtualenv,在 Ruby 和 Python 社区中被广泛认为是最佳实践
在可能的情况下下载一个预编译的二进制文件,如果没有,它会下载源代码并为您编译一个
我们可以通过以下方式轻松切换节点版本:
nvm install 0.9.0
nvm install 0.9.9
nvm use 0.9.0
node --version
#v0.9.0
nvm use 0.9.9
node --version
#v0.9.9
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用 git 跟踪.nvmrc
文件来指示给定项目所需的节点版本:https : //stackoverflow.com/questions/24869959/how-do-i-specify-a-local-version-of-node-for -a-project/54503474#54503474
通过此设置,您将获得例如:
which node
Run Code Online (Sandbox Code Playgroud)
给出:
/home/ciro/.nvm/versions/node/v0.9.0/bin/node
Run Code Online (Sandbox Code Playgroud)
和:
which vaca
Run Code Online (Sandbox Code Playgroud)
给出:
/home/ciro/.nvm/versions/node/v0.9.0/bin/vaca
Run Code Online (Sandbox Code Playgroud)
如果我们想使用全局安装的模块:
npm link vaca
node -e 'console.log(require.resolve("vaca"))'
Run Code Online (Sandbox Code Playgroud)
给出:
/home/ciro/.nvm/versions/node/v0.9.0/lib/node_modules/vaca/index.js
Run Code Online (Sandbox Code Playgroud)
所以我们看到所有内容都完全包含在特定节点版本中。
在 Ubuntu 17.10 中测试。
卸载以前版本的节点 -
\nsudo apt remove node && sudo apt autoremove
转至https://nodejs.org/en/并下载最新版本的\nnode。
\n现在打开终端并更改下载节点的目录\n然后运行-
\ntar -xvf node-v12.16.2-linux-x64.tar.xz
现在在终端中运行它 -
\nnano ~/.bashrc
并附加以下 \xe2\x80\x93
\n export PATH=/path/to/node-js/bin:$PATH
\n其中,\n /path/to/node-js/将替换为您在步骤 3 中提取节点的位置。`
运行最后一个命令source ~/.bashrc
就是这样。
\n现在您可以通过以下方式检查您的节点版本node -v