如何将NodeJS和NPM更新到下一版本?

node.js Node.js

Eva西里

2020-03-13

我刚刚安装了Node.jsnpm(用于其他模块)。

如何将Node.js和正在使用的模块更新到最新版本?

可以npm这样做,还是必须删除并重新安装Node.js和npm才能获得下一个版本?

在本节中遵循了步骤npm

第1433篇《如何将NodeJS和NPM更新到下一版本?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

26个回答
番长Jim路易 2020.03.13

只需在控制台上运行以下脚本:

sudo npm i -g n
sudo n stable
sudo npm update -g npm

这仅适用于Linux和MAC

A十三 2020.03.13

如果您使用的是Windows:请访问https://nodejs.org/en/download/,下载最新版本.exe.msi文件并进行安装以覆盖旧版本

如果您使用的是Ubuntu或Linux:node.js首先卸载,然后重新安装,例如使用Ubuntu():

sudo apt-get remove nodejs

# assume node.js 8 is latest version
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install nodejs

node -v
npm -v

删除node_modules项目中的文件夹,npm install以确保您的应用程序将在新井运行nodenpm版本。

卡卡西理查德 2020.03.13

使用npm中的n模块以升级node。n是一个节点帮助程序包,用于安装或更新给定的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/nodejs

注意,nodejs的默认安装位于/ usr / bin / nodejs中,而不是/ usr / bin / node中

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

sudo n latest

撤销:

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

如果收到以下错误,bash: /usr/bin/node: No such file or directory则输入的路径

sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs

如果有错。因此,请确保检查以上路径中是否已安装更新nodejs以及输入的版本是否正确。

强烈建议不要生产实例上执行此操作它会严重破坏您的全局npm软件包和您安装新软件包的能力。

小胖蛋蛋 2020.03.13

另外,如果您想更新到特定版本,请遵循以下步骤:

sudo npm cache clean -f
sudo npm install -g n
sudo n <specific version>
otaku若 2020.03.13

对于nodejs,应将其卸载并从nodejs.org下载您喜欢的版本,以使npm在cmd中的行下运行:

npm i npm
阳光Tom逆天 2020.03.13

When it comes to Linux I suggest an Update Node Using a Package Manager:

Node comes with npm pre-installed, but the manager is updated more frequently than Node. Run npm -v to see which version you have, then npm install npm@latest -g to install the newest npm update. Run npm -v again if you want to make sure npm updated correctly.

To update NodeJS, you’ll need npm’s handy n module. Run this code to clear npm’s cache, install n, and install the latest stable version of Node:

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

To install the latest release, use n latest. Alternatively, you can run n #.#.# to get a specific Node version.


When it comes to Windows/ macOS I suggest using Installers on Nodejs.org

The Node.js downloads page includes binary packages for Windows and macOS — but why make your life more difficult? The pre-made installers — .msi for Windows and .pkg for macOS — make the installation process unbelievably efficient and understandable. Download and run the file, and let the installation wizard take care of the rest. With each downloaded update, the newer versions of Node and npm will replace the older version.

Alternatively, macOS users can use the npm and n instructions above.


When it comes to updating your node_modules dependencies folder, I suggest skipping all the things that could cause you a headache and just go to your specific project and re-run npm install again.

Before anyone does that, I suggest first checking your package.json file for the following:

作为NodeJS软件包的用户,您可以在package.json文件中指定应用程序可以接受的更新类型。例如,如果您从软件包版本1.0.4开始,则可以通过以下三种基本方式指定允许的更新版本范围:

允许补丁发布:1.0或1.0.x或〜1.0.4
允许次要版本:1或1.x或^ 1.0.4
允许主要版本:*或x

说明:

API版本不兼容时的主要版本。->~

MINOR版本,用于以向后兼容的方式添加功能时。->^

完成向后兼容错误修复时的 PATCH版本。->*

路易卡卡西 2020.03.13

更新npm:

npm install npm@{version} -g

将npm更新到最新版本:

npm install npm@latest -g

并检查版本:

npm -v

更新节点js:

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

去检查 :

node -v
Sam飞云 2020.03.13

仅与此代码

npm install update
乐十三 2020.03.13

只是听与NPM队的最新一集的采访nodeup,和他们建议使用update从更新1.x2.x而是使用: npm install npm -g

逆天米亚 2020.03.13

有时从http://nodejs.org/下载最新版本会更简单

特别是当所有其他选项均失败时。

http://nodejs.org/- >单击安装->您将拥有最新的节点和npm

简单!

Sam神奇A 2020.03.13

我最近偶然发现了这篇文章:http : //martineau.tv/blog/2013/12/more-ficient-grunt-workflows/,作者提到$ npm-check-updates -u && npm install要更新所有依赖项。

这与主题略有出入,但我在这里进行了类似的搜索,因此值得分享。

Tony老丝 2020.03.13

只需以root / administrator身份在终端中运行以下命令:

npm i -g n
n stable
npm update -g npm

它在Linux上对我有用

梅乐 2020.03.13

适用于Linux,OSX等。

安装最新版本的NPM

npm install -g npm@latest

或安装最新版本

npm install -g npm@next

其他:检查您的npm版本

npm -v

如果您使用Windows机器,建议您访问npm网站

番长斯丁 2020.03.13

我认为管理node.js的最佳方法是使用NVM NVM代表节点版本管理器。

这是node.js开发人员的必备工具!

您可以使用以下命令安装NVM,打开终端并运行以下任意一项:-

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

要么

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

安装此程序后,建议关闭当前终端并打开一个新终端,因为NVM将添加一些环境变量,因此需要重新启动终端。

我将列出一些使用NVM的基本命令。

  • 这将从互联网上获取所有节点版本。将显示从开始到日期的所有节点版本,同时还会提及LTS版本。
nvm ls-remote 
  • 这将安装您想要的节点版本(使用上面的命令获得版本列表)
nvm install v10.15.1
  • 该命令将为我们提供本地安装的节点版本的列表
nvm ls
  • 此命令用于从计算机中删除所需的节点版本
nvm uninstall v10.15.1
  • 以下命令将帮助您升级到npm当前节点版本上的最新版本
nvm install-latest-npm
  • NVM可用于同时管理多个节点版本
  • 它还可以帮助您将所有全局npm软件包从一个版本安装到另一个版本,而不是手动安装每个版本!
  • nvm还有许多其他用途,其详细信息和命令可在此处找到。节点版本管理器
乐理查德 2020.03.13

安装npm =>sudo apt-get install npm

安装n =>sudo npm install n -g

最新版本的节点 =>sudo n latest

可以的特定版本的节点

列出可用的节点版本 =>n ls

安装特定版本 =>sudo n 4.5.0

小胖Green 2020.03.13

我刚刚在新的Windows 7计算机上安装了Node.js,结果如下:

> node -v
v0.12.0
> npm -v
2.5.1

然后,我执行了上述过程:

> npm install -g npm

并升级到v2.7.3。除了比做npm -v还给2.5.1。

我去了系统配置面板,高级设置,环境变量。除了全局Path变量之外,我还看到了特定于我的用户帐户的PATH变量。
前者指向新的npm:C:\Users\PhiLho\AppData\Roaming\npm
后者包括指向节点的路径:(C:\PrgCmdLine\nodejs\现在,我避免在Program Files和衍生产品中安装内容。避免在路径中留空格,并且嘈杂的无用保护措施更为合理...)
如果我这样做which npm.cmd(我有已安装Unix实用程序...),它指向Node中的一个。

无论如何,解决方法很简单:我只是将第一个路径(到npm)复制到了主要全局变量Path中节点的路径之前,现在它获取了最新版本。
<some stuff before>;C:\Users\PhiLho\AppData\Roaming\npm;C:\PrgCmdLine\nodejs\

> npm -v
2.7.3

请享用。:-)

Near飞云 2020.03.13
$ npm install -g npm stable

为我工作从1.4.28更新到2.1.5

老丝飞云 2020.03.13
  • 更新节点使用NVM(或nvmw适用于Windows)。

  • 更新npm,该npm update npm -g命令对我不起作用(在Windows上)。根据文档,重新安装npm的工作是:“ 您可以从https://npmjs.org/dist/下载zip文件,然后将其解压缩到node.exe所在的文件夹中。 ”确保是否执行此操作您首先要摆脱先前的安装(尽管覆盖它可能会正常工作...)。

  • 更新模块,请使用npm update命令

GOLEY前端 2020.03.13

简单使用此

npm i -g npm

当发布新的更新/错误修复时,这是我从npm提示在控制台上的内容:

在此处输入图片说明

小宇宙猪猪 2020.03.13

第一次更新npm

npm install -g npm@next

然后更新node到下一个版本,

npm install -g node@nextnpm install -g n@next 或者,最新

npm install -g node@latest 要么 npm install -g node

安装版本后检查

node --version要么 node -v

米亚Sam 2020.03.13

Windows用户升级

Windows用户应在npm Wiki中阅读故障排除> Windows上的升级

使用PowerShell在Windows 10上进行升级(第三方编辑)

Windows疑难解答#upgradeing上方的链接指向github页面npm-windows-upgrade,以下行是自述文件的引号。我已使用节点v5.7.0和powershell(大概是powershell版本5.0.10586.122)成功地从npm 2.7.4升级到了npm 3.9.3。

首先,通过从提升的PowerShell中运行以下命令,确保可以在系统上执行脚本。要以管理员身份运行PowerShell,请单击开始,搜索PowerShell,右键单击PowerShell,然后选择以管理员身份运行。

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force    

然后,要安装和使用此升级程序工具,请运行(也可以从提升的PowerShell或cmd.exe)运行:

npm install --global --production npm-windows-upgrade
npm-windows-upgrade
乐ASam 2020.03.13

首先检查您的NPM版本

npm -v

1)将NPM更新为当前版本:

查看当前NPM版本:

npm view npm version

将npm更新到当前版本:

npm i -g npm


2)列出所有可用的NPM版本并进行自定义安装/更新/回滚

查看所有版本,包括“ alpha”,“ beta”和“ rc”(候选发行版)

npm view npm versions --json

将NPM重新安装到从版本列表中选择的特定版本-例如到5.0.3

npm i -g npm@5.0.3
  • 安装一个版本将自动删除当前安装的版本。

  • 对于Linux和iOS,使用sudo前缀命令

米亚西里 2020.03.13

我知道这个问题是针对Linux机器的,但是以防万一有人在寻找Windows解决方案,只需转到Node.js站点,单击主页上的下载按钮并执行安装程序即可。

幸运的是,它可以处理所有事情,单击“下一步”按钮,我在Windows 7计算机上运行了最新的0.8.15 Node.js版本。

斯丁Jim 2020.03.13

更新npm很容易:

npm install npm@latest -g
达蒙JinJin 2020.03.13

我在David Walsh的博客上发现了这种更新节点的好方法,您可以通过安装n以下方法来完成

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

它将安装的当前稳定版本node


编辑:请不要再使用n了。我建议使用nvm您可以按照以下命令简单地安装稳定版:

nvm ls-remote
nvm install <version> 
nvm use <version>
Harry逆天Eva 2020.03.13

有关update命令,请参阅文档

npm update [-g] [<pkg>...]

This command will update all the packages listed to the latest version (specified by the tag config), respecting semver.

Additionally, see the documentation on Node.js and NPM installation and Upgrading NPM.

The following original answer is from the old FAQ that no longer exists, but should work for Linux and Mac:

How do I update npm?

npm install -g npm

Please note that this command will remove your current version of npm. Make sure to use sudo npm install -g npm if on a Mac.

You can also update all outdated local packages by doing npm update without any arguments, or global packages by doing npm update -g.

Occasionally, the version of npm will progress such that the current version cannot be properly installed with the version that you have installed already. (Consider, if there is ever a bug in the update command.) In those cases, you can do this:

curl https://www.npmjs.com/install.sh | sh

To update Node.js itself, I recommend you use nvm, the Node Version Manager.

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android