将 Node.js 升级到最新版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10075990/
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
Upgrading Node.js to latest version
提问by holyredbeard
So, I have Node.js installed and now when I tried to install Mongoosejs I got an error telling me that I don't have the needed version of Node.js (I have v0.4.11 and v0.4.12 is needed).
所以,我已经安装了 Node.js,现在当我尝试安装 Mongoosejs 时出现错误,告诉我我没有所需的 Node.js 版本(我需要 v0.4.11 和 v0.4.12)。
How can I upgrade to this version? I suppose I just could install it again with the latest version, but I don't want to do it before I'm sure that my project folders in the folder "node" won't be deleted.
我怎样才能升级到这个版本?我想我可以用最新版本再次安装它,但是在我确定文件夹“node”中的项目文件夹不会被删除之前,我不想这样做。
回答by Eldar Djafarov
Linux/Mac:
Linux/Mac:
The module nmakes version-management easy:
该模块n使版本管理变得容易:
sudo npm install n -g
For the latest stable version:
对于最新的稳定版本:
sudo n stable
For the latest version:
对于最新版本:
sudo n latest
Windows:
视窗:
just reinstall node from the .msi in Windows from the node website.
只需从节点网站从 Windows 中的 .msi 重新安装节点。
回答by nelsonic
1 Minute Solution Withoutusing sudo:
1 分钟解决方案,无需使用sudo:
The current stable "LTS" version of node is 12.17.0(2020-05-27) see: nodejs.orgfor latest.
当前稳定的“LTS”节点版本为12.17.0( 2020-05-27),请参阅:nodejs.org了解最新版本。
Step 1 - Get NVM(Node Version Manger)
第 1 步 -获取NVM(节点版本管理器)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
If you're curiousabout the installation command readthe source code
... its been reviewedby severalnode.js security experts
如果你好奇的有关安装命令读取的源代码
...它已通过几个node.js的安全专家
Step 2 - Installthe version of node.js you need
第 2 步 -安装您需要的 node.js 版本
Once you've got NVMyou can install a specificversion of Node.js using the nvm command:
获得NVM 后,您可以使用 nvm 命令安装特定版本的 Node.js:
nvm install v12.17.0
Note: you may need to close & re-open your terminal window for nvmcommand to be available.
注意:您可能需要关闭并重新打开终端窗口才能使用nvm命令。
You should expect to see something like this in your terminal:
您应该期望在终端中看到类似的内容:
Now using node v12.17.0
Step 3 - Enjoythe rest of your day!
第 3 步 -享受剩下的一天吧!
Yes, it's that easyand didn't require sudo!
Now please Upvotethis (so others can avoid sudo-installing things!)
and have a lovely daywriting node.js code!
是的,就这么简单,不需要sudo!
现在请点赞(这样其他人就可以避免sudo安装东西!)
并有一个美好的一天编写 node.js 代码!
Microsoft WindowsUser? Use: https://github.com/coreybutler/nvm-windows
微软视窗用户?使用:https: //github.com/coreybutler/nvm-windows
?tl;dr
?tl;博士
Review of the node mailing list indicates that using NVM(Node Version Manager) is the preferredway to manage your nodejs versioning/upgrading. see: github.com/nvm-sh/nvm
查看节点邮件列表表明,使用NVM(节点版本管理器)是管理 nodejs 版本控制/升级的首选方式。见:github.com/nvm-sh/nvm
NVMis considered "better" than Nbecause the verbosecommands mean is mucheasier to keep track of what you are doing in your Terminal/SSH Log. Its also faster, saves kittensby not requiringsudoand is used by the team at NPMthe node.js security experts!
NVM被认为比N“更好”,因为冗长的命令意味着更容易跟踪您在终端/SSH 日志中所做的事情。它也更快,不需要小猫就可以拯救小猫,并且被NPM团队的 node.js安全专家使用!sudo
回答by Glats
回答by Osman Erdi
On Windowsdownload latest "Windows Installer (.msi)" from https://nodejs.org/download/release/latest/and install same directory , thats all...
在 Windows 上从https://nodejs.org/download/release/latest/下载最新的“Windows Installer (.msi)” 并安装相同的目录,仅此而已...
After complete the installation above, the NodeJS and NPM will be upgraded to the latest one and then you can cleanup the package as normal as:
完成上述安装后,NodeJS和NPM将升级到最新版本,然后您可以正常清理包:
npm cache clean
npm update -g
Note
笔记
You can always check the version with following command:
您始终可以使用以下命令检查版本:
C:\node -v
v0.12.4
C:\npm -version
2.10.1
回答by swelet
All platforms (Windows, Mac & Linux)
所有平台(Windows、Mac 和 Linux)
Just go to nodejs.organd download the latest installer.It couldn't be any simpler honestly, and without involvement of any third-party stuff. It only takes a minute and does not require you to restart anything or clean out caches, etc.
只需转到nodejs.org并下载最新的安装程序。老实说,它再简单不过了,而且不涉及任何第三方的东西。它只需要一分钟,不需要您重新启动任何东西或清除缓存等。
I've done it via npm a few times before and have run into a few issues. Like for example with the n-package not using the latest stable release.
我之前通过 npm 做过几次,但遇到了一些问题。例如,n-package 不使用最新的稳定版本。
回答by Jon Crowell
Upgrading node.js to the latest version on Windows
在 Windows 上将 node.js 升级到最新版本
Install chocolatey if you haven't already: Installing Chocolatey
From the command prompt, type
cup nodejs
如果您还没有安装 Chocolatey: 安装 Chocolatey
在命令提示符下,键入
cup nodejs
(which is equivalent to typing choco upgrade nodejs-- assumes you already have node installed)
(这相当于打字choco upgrade nodejs——假设你已经安装了节点)
NOTE: You may need to run cinst nodejs.installfor chocolatey to register your existing installation. (thanks for the comment, @mikecheel)
注意:您可能需要运行cinst nodejs.installChocolatey 才能注册您现有的安装。(感谢评论,@mikecheel)
Installing node.js on Windows
在 Windows 上安装 node.js
If you have never installed node, you can use chocolatey to do that as well. Install chocolatey (see step 1 above). Then from a command prompt, type:
如果您从未安装过 node,您也可以使用 Chocolatey 来安装。安装巧克力(参见上面的步骤 1)。然后从命令提示符键入:
cinst nodejs.install
cinst nodejs.install
Chocolatey Gallery Node JS (Install)
Chocolatey Gallery Node JS(安装)
Installing a specific version of node on Windows with chocolatey
在 Windows 上使用 Chocolatey 安装特定版本的节点
cinst nodejs.install -Version 0.10.26
cinst nodejs.install -Version 0.10.26
回答by Sagar Jethi
Following Upgrading Node.js to latest version
将 Node.js 升级到最新版本之后
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/node
For Upgrading Node.js to latest version
用于将 Node.js 升级到最新版本
sudo n latest
If you need to do Undo then follow command
如果您需要撤消,请遵循命令
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
This method of upgrading node is now unstable and should not be used. The best way to manage Node.js versions is to use NVM: Node Version Management.!
这种升级节点的方法现在不稳定,不应该使用。管理 Node.js 版本的最佳方式是使用 NVM:节点版本管理。!
Installation
安装
You can read the installation steps on the nvm [GitHub page][1]. There are only two easy steps for installation and configuration. Using nvm
您可以在 nvm [GitHub 页面][1] 上阅读安装步骤。安装和配置只有两个简单的步骤。使用 nvm
If you work with a lot of different Node.js utilities, you know that sometimes you need to quickly switch to other versions of Node.js without hosing your entire machine. That's where you can use nvm to download, install, and use different versions of Node.js:
如果您使用过许多不同的 Node.js 实用程序,您就会知道有时您需要快速切换到其他版本的 Node.js,而无需安装整台机器。您可以在此处使用 nvm 下载、安装和使用不同版本的 Node.js:
nvm install 4.0
At any given time you can switch to another with use:
在任何给定时间,您都可以使用以下命令切换到另一个:
nvm use 0.12
回答by agconti
For brew users on Mac OSX
对于 Mac OSX 上的 brew 用户
brew upgrade node
Which produces:
其中产生:
Andrews-MacBook-Air :: ~/dev/cookiecutter-ionic ?master*? ? brew upgrade node
==> Upgrading 1 outdated package, with result:
node 0.12.7
==> Upgrading node
==> Downloading https://homebrew.bintray.com/bottles/node-0.12.7.yosemite.bottle
######################################################################## 100.0%
==> Pouring node-0.12.7.yosemite.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
/usr/local/Cellar/node/0.12.7: 2726 files, 31M
回答by Gurudath BN
Install npm=>
安装 npm=>
sudo apt-get install npm
Install n=>
安装 n=>
sudo npm install n -g
latest version of node=>
最新版本的节点=>
sudo n latest
So latest version will be downloaded and installed
因此将下载并安装最新版本
Specific version of node you can
您可以使用特定版本的节点
List available node versions=>
列出可用的节点版本=>
n ls
Install a specific version=>
安装特定版本=>
sudo n 4.5.0
回答by Sharath
I had node version v7.10.0in Ubuntu
我在 Ubuntu 中有节点版本v7.10.0
Used below commands to upgrade
使用以下命令进行升级
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
Now its upgraded to v8.2.1
现在它升级到v8.2.1
or
或者
sudo apt-get install make
sudo curl -L https://git.io/n-install | bash
. /home/$USER/.bashrc
# Below command should get the latest version of node
node --version
# Install specific version of node
n 8.2
# Check for the Node Version installed
node --version

