在 ubuntu 16.04 上更新 nodejs

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41195952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:52:41  来源:igfitidea点击:

updating nodejs on ubuntu 16.04

node.jsubuntu

提问by ankur

I was recently going through the version of node in my ubuntu 16.04 when node -vcommand was used it shows me version 6.9.1 but when nodejs -vit shows 6.9.2 previously before using this commands npm updatecommand was used.

我最近在node -v使用命令时浏览了 ubuntu 16.04 中的 node 版本,它显示了 6.9.1 版,但是nodejs -v在使用此命令之前,它显示了 6.9.2版npm update

Now what's these difference in node -vand nodejs -v? and how to update to the latest LTS version of node/nodejs?

现在,什么是在这些差异node -vnodejs -v?以及如何更新到 node/nodejs 的最新 LTS 版本?

回答by Camille Gerin-Roze

To update, you can install n

要更新,您可以安装 n

sudo npm install -g n

Then just :

然后只是:

sudo n latest

or a specific version

或特定版本

sudo n 8.9.0

回答by Developia

According to official docsto install node on Debian and Ubuntu based distributions:

根据官方的文档,以安装在基于Debian和Ubuntu发行节点

node v10(Old):

节点 v10(旧):

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

node v12 LTS(For new users: install this one):

node v12 LTS(对于新用户:安装这个):

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

node v13:

节点 v13

curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install -y nodejs

node v14(Current version):

节点 v14(当前版本):

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

Other older versions:Just replace the desired version number in the link above.

其他旧版本:只需替换上面链接中所需的版本号。

Optional:install build tools

可选:安装构建工具

To compile and install native packages

编译和安装本机包

sudo apt-get install -y build-essential

To update nodeto latest version just:

要将节点更新到最新版本:

sudo apt update
sudo apt upgrade

To keep npmupdated

保持npm更新

sudo npm i -g npm

To find out other versions try npm info npmand in versions find your desired version and replace [version-tag] with that version tag in npm i -g npm@[version-tag]

要找出其他版本,请尝试npm info npm在版本中找到您想要的版本并将 [version-tag] 替换为该版本标签npm i -g npm@[version-tag]

And I also recommend try yarninstead of npm

而且我还建议尝试使用yarn而不是 npm

回答by Ahmad Abdelghany

Using Node Version Manager (NVM):

使用节点版本管理器(NVM)

Install it:

安装它:

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

Test your installation:

测试您的安装:

close your current terminal, open a new terminal, and run:

关闭当前终端,打开一个新终端,然后运行:

command -v nvm

Use it to install as many versions as u like:

使用它来安装任意数量的版本:

nvm install 8              # Install nodejs 8
nvm install --lts          # Install latest LTS (Long Term Support) version

List installed versions:

列出已安装的版本:

nvm ls

Use a specific version:

使用特定版本:

nvm use 8                  # Use this version on this shell

Set defaults:

设置默认值:

nvm alias default 8        # Default to nodejs 8 on this shell
nvm alias default node     # always use latest available as default nodejs for all shells

回答by DarkKnight

Use sudo apt-get install --only-upgrade nodejsto upgrade node (and only upgradenode) using the package manager.

用于使用包管理器sudo apt-get install --only-upgrade nodejs升级节点(并且仅升级节点)。

The package name is nodejs, see https://stackoverflow.com/a/18130296/4578017for details.

包名是nodejs,详见https://stackoverflow.com/a/18130296/4578017

You can also use nvmto install and update node.

您还可以nvm用于安装和更新节点。

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash

Then restart the terminal, use nvm ls-remoteto get latest version list of node, and use nvm install lts/*to install latest LTS version.

然后重启终端,用于nvm ls-remote获取节点最新版本列表,nvm install lts/*用于安装最新的LTS版本。

nvmis more recommended way to install or update node, even if you are not going to switch versions.

nvm即使您不打算切换版本,也是更推荐的安装或更新节点的方式。

回答by Siva Kiran

Difference: When I first installed node, it installed as 'nodejs'. When I upgraded it, it created 'node'. By executing node, we are actually executing nodejs. Node is just a reference to nodejs. From my experience, when I upgraded, it affected both the versions (as it is supposed to). When I do nodejs -v or node -v, I get the new version.

区别:当我第一次安装节点时,它安装为'nodejs'。当我升级它时,它创建了“节点”。通过执行node,我们实际上是在执行nodejs。Node 只是对 nodejs 的引用。根据我的经验,当我升级时,它影响了两个版本(正如预期的那样)。当我执行 nodejs -v 或 node -v 时,我得到了新版本。

Upgrading: npm update is used to update the packages in the current directory. Check https://docs.npmjs.com/cli/update

升级: npm update 用于更新当前目录下的包。检查https://docs.npmjs.com/cli/update

To upgrade node version, based on the OS you are using, follow the commands here https://nodejs.org/en/download/package-manager/

要根据您使用的操作系统升级节点版本,请按照此处的命令https://nodejs.org/en/download/package-manager/

回答by Mahak Choudhary

Use n module from npmin order to upgrade node

使用npm中的n 模块来升级节点

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

To upgrade to latest version (and not current stable) version, you can use

要升级到最新版本(而不是当前稳定的)版本,您可以使用

sudo n latest

Undo :

撤消:

sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/node sudo n rm 6.0.0 # replace number with version of Node that was installed sudo npm uninstall -g n

sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/node sudo n rm 6.0.0 # 用安装的 Node 版本替换数字 sudo npm uninstall -gn

回答by Rubel Hossain

sudo npm install npm@latest -g

回答by Naresh

Please refer nodejs official site for installation instructions at the following link

安装说明请参考nodejs官网以下链接

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

Anyway, please find the commands to install nodejs version 10 in ubuntu below.

无论如何,请在下面找到在 ubuntu 中安装 nodejs 版本 10 的命令。

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

回答by Guile Garcia

Try this:

尝试这个:

Edit or create the file :nodesource.list

编辑或创建文件 :nodesource.list

sudo gedit /etc/apt/sources.list.d/nodesource.list

Insert this text:

插入这段文字:

deb https://deb.nodesource.com/node_10.xbionic main

deb-src https://deb.nodesource.com/node_10.xbionic main

deb https://deb.nodesource.com/node_10.x仿生主

deb-src https://deb.nodesource.com/node_10.x仿生主

Run these commands:

运行这些命令:

curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -


sudo sh -c "echo deb https://deb.nodesource.com/node_10.x cosmic main /etc/apt/sources.list.d/nodesource.list"

sudo apt-get update

sudo apt-get install nodejs

回答by Anandhu Raj

Run these commands:

运行这些命令:

sudo apt-get update
sudo apt-get install build-essential libssl-dev
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
source ~/.profile
nvm ls-remote
nvm install v9.10.1
nvm use v9.10.1
node -v