I just installed Node.js
and npm
(for additional modules).
我刚刚安装了Node.js和npm(用于其他模块)。
How can I update Node.js and the modules which I'm using to the latest versions?
如何将Node.js和我正在使用的模块更新到最新版本?
Can npm
do it, or do I have to remove and reinstall Node.js and npm to get the next versions?
可以npm这样做,还是我必须删除并重新安装Node.js和npm才能获得下一个版本?
I followed this steps in the npm
section.
我在npm部分中执行了这些步骤。
35 个解决方案
#1
1419
See the docs for the update
command:
请参阅update命令的文档:
npm update [<name> [<name> ...]]
This command will update all the packages listed to the latest version (specified by the tag config). It will also install missing packages.
此命令将更新列出的最新版本的所有软件包(由标记配置指定)。它还将安装缺少的包。
Additionally, see the FAQ:
另外,请参阅常见问题:
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.请注意,此命令将删除当前版本的npm。如果在Mac上,请务必使用sudo npm install -g npm。
You can also update all outdated local packages by doing
npm update
without any arguments, or global packages by doingnpm update -g
.您还可以通过执行npm update而不使用任何参数来更新所有过时的本地程序包,或者通过执行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:
有时,npm的版本会进展,以至于无法使用已安装的版本正确安装当前版本。 (如果update命令中有错误,请考虑。)在这些情况下,您可以这样做:
curl https://www.npmjs.com/install.sh | sh
To update Node.js itself, I recommend you use nvm, the Node Version Manager.
要更新Node.js本身,我建议您使用节点版本管理器nvm。
#2
355
I found this really neat way of updating node on David Walsh's blog, you can do it by installing n
:
我在David Walsh的博客上发现了这种更新节点的方法,你可以通过安装n来实现:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
It will install the current stable version of node
. However, I recommend using nvm
.
它将安装当前稳定版本的节点。但是,我建议使用nvm。
#3
176
Updating npm is easy:
更新npm很简单:
npm install npm@latest -g
#4
127
I understand this question is for Linux machine but just in case anybody is looking for a Windows solution, just go to the Node.js site, click the download button on the homepage and execute the installer program.
我理解这个问题适用于Linux机器,但万一有人正在寻找Windows解决方案,只需转到Node.js站点,单击主页上的下载按钮并执行安装程序。
Thankfully it took care of everything and with a few clicks of 'Next' button I got the latest 0.8.15 Node.js version running on my Windows 7 machine.
值得庆幸的是,它完成了一切,只需点击几下“下一步”按钮,我就可以在Windows 7机器上运行最新的0.8.15 Node.js版本。
#5
101
As you may know, NPM is currently bundled with Node.js, it means that if you have installed node
you already have installed npm
. There are several approaches to keep up to date the Node.js and NPM, you need to use one of the following version managers:
您可能知道,NPM目前与Node.js捆绑在一起,这意味着如果您已经安装了节点,那么您已经安装了npm。有几种方法可以保持最新的Node.js和NPM,您需要使用以下版本管理器之一:
Homebrew
If yo are on Mac, you can use Homebrew. To install NodeJS and NPM using brew:
如果你在Mac上,你可以使用Homebrew。使用brew安装NodeJS和NPM:
$ brew install node
later you will be able to update it using
稍后您将能够使用更新它
$ brew update && brew upgrade node
NPM will be updated as well.
NPM也将更新。
You also will be able to switch
to the one of the previous versions if you need, for example:
如果需要,您还可以切换到以前的版本之一,例如:
$ brew switch node 0.10.26
To install brew to your Mac:
要将brew安装到Mac:
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
N
n is most likely to rvm
(Ruby Version Manager), and can be used to manage and update node/npm
versions.
n最有可能是rvm(Ruby Version Manager),可用于管理和更新node / npm版本。
Install Node.js versions easily:
轻松安装Node.js版本:
$ n 0.10.26
$ n 0.8.17
$ n 0.9.6
Use (and install if missing) the latest official release:
使用(如果缺少则安装)最新的官方发布:
$ n latest
Use/install the stable official release:
使用/安装稳定的官方发布:
$ n stable
Switch to the previous version you were using:
切换到您使用的先前版本:
$ n prev
If you want to see the list of installed nodes, just run n
from your command line, the output will be something like the following:
如果要查看已安装节点的列表,只需从命令行运行n,输出将如下所示:
$ n
0.10.26
• 0.8.17
0.9.6
The dot (•) means that it's a currently active version. To select a node version from the list use up
and down
arrows and activate using enter
.
点(•)表示它是当前活动的版本。要从列表中选择节点版本,请使用向上和向下箭头并使用enter激活。
The n
package is written on pure linux shell
and available as a npm module (contains package.json
), so if you have any Node.js installed, you can install/update the n
through the npm
:
n包是在纯linux shell上编写的,可以作为npm模块(包含package.json)使用,所以如果你安装了任何Node.js,你可以通过npm安装/更新n:
$ npm install -g n
NVM
nvm is also like RVM
, even the command names and usage are very similar.
nvm也像RVM一样,甚至命令名和用法都非常相似。
To download, compile, and install the latest v0.10.x release of the Node.js using nvm
:
使用nvm下载,编译和安装Node.js的最新v0.10.x版本:
$ nvm install 0.10
And then you can switch to the installed version:
然后您可以切换到已安装的版本:
$ nvm use 0.10
You can create an .nvmrc
file containing version number in the project root folder; then run the following command to switch to the specified version:
您可以在项目根文件夹中创建包含版本号的.nvmrc文件;然后运行以下命令切换到指定的版本:
$ nvm use
Or you can just run it:
或者你可以运行它:
$ nvm run 0.10
If you want to see which versions are already installed, use:
如果要查看已安装的版本,请使用:
$ nvm ls
To install nvm
itself you can use the install script (requires git
) using cURL
:
要安装nvm本身,您可以使用cURL使用安装脚本(需要git):
$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh
or wget
:
$ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
P.S.
All these approaches I've used on MacOSX and Linux, I don't have any experience on how to manage Node.js versions on Windows, I can only suppose that the n
(the second one) will work for Microsoft's OS (at least from the cygwin
).
我在MacOSX和Linux上使用的所有这些方法,我没有任何关于如何在Windows上管理Node.js版本的经验,我只能假设n(第二个)将适用于Microsoft的操作系统(至少来自cygwin)。
#6
86
First check your NPM version
npm -v
1) Update NPM to current version:
View curent NPM version:
查看curent NPM版本:
npm view npm version
Update npm to current version:
将npm更新为当前版本:
npm i -g npm
2) List all available NPM versions and make a custom install/update/roll-back
View all versions including "alpha", "beta" and "rc" (release candidate)
查看所有版本,包括“alpha”,“beta”和“rc”(发布候选版)
npm view npm versions --json
Reinstall NPM to a specific version chosen from the versions list - for example to 5.0.3
将NPM重新安装到从版本列表中选择的特定版本 - 例如5.0.3
npm i -g npm@5.0.3
-
Installing one version will automatically remove the one currently installed.
安装一个版本将自动删除当前安装的版本。
-
For Linux and iOS prepend commands with sudo
对于Linux和iOS,使用sudo前置命令
#7
49
Upgrading for Windows Users
Windows users should read Troubleshooting > Upgrading on Windows in the npm wiki.
Windows用户应阅读npm wiki中的“故障排除”>“在Windows上升级”。
Upgrading on windows 10 using PowerShell (3rd party edit)
The link above Troubleshooting#upgrading-on-windows points to a github page npm-windows-upgrade the lines below are quotes from the readme. I successfully upgraded from npm 2.7.4 to npm 3.9.3 using node v5.7.0 and powershell (presumably powershell version 5.0.10586.122)
故障排除#regrade-on-windows上面的链接指向github页面npm-windows-upgrade下面的行是自述文件中的引号。我使用node v5.7.0和powershell(大概是powershell版本5.0.10586.122)成功地从npm 2.7.4升级到npm 3.9.3
First, ensure that you can execute scripts on your system by running the following command from an elevated PowerShell. To run PowerShell as Administrator, click Start, search for PowerShell, right-click PowerShell and select Run as Administrator.
首先,通过从提升的PowerShell运行以下命令,确保您可以在系统上执行脚本。要以管理员身份运行PowerShell,请单击“开始”,搜索PowerShell,右键单击“PowerShell”,然后选择“以管理员身份运行”。
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
Then, to install and use this upgrader tool, run (also from an elevated PowerShell or cmd.exe):
然后,要安装并使用此升级工具,请运行(也可以从提升的PowerShell或cmd.exe):
npm install --global --production npm-windows-upgrade
npm-windows-upgrade
#8
45
First update npm
,
第一次更新npm,
npm install -g npm@next
npm install -g npm @ next
Then update node
to the next version,
然后将节点更新到下一个版本,
npm install -g node@next
or npm install -g n@next
or, to the latest,
npm install -g node @ next或npm install -g n @ next或者到最新的,
npm install -g node@latest
or npm install -g node
npm install -g node @ latest或npm install -g node
check after version installation,
版本安装后检查,
node --version
or node -v
node --versionor node -v
#9
#10
25
-
To update node use nvm (or nvmw for windows).
要更新节点,请使用nvm(或nvmw for windows)。
-
To update npm, the
npm update npm -g
command didn't work for me (on windows). What did work was reinstalling npm according to the documentation: "You can download a zip file from https://npmjs.org/dist/, and unpack it in the same folder where node.exe lives." Make sure if you do this that you get rid of your previous installation first (though overwriting it will probably work ok...).要更新npm,npm update npm -g命令对我不起作用(在Windows上)。根据文档重新安装npm的工作是什么:“你可以从https://npmjs.org/dist/下载一个zip文件,然后将它解压缩到node.exe所在的同一个文件夹中。”确保如果你这样做,你先摆脱以前的安装(虽然覆盖它可能会正常工作......)。
-
To update your modules, use the npm update command
要更新模块,请使用npm update命令
#11
17
$ npm install -g npm stable
Worked for me to update from 1.4.28 to 2.1.5
我的工作是从1.4.28更新到2.1.5
#12
14
I just installed Node.js on a new Windows 7 machine, with the following results:
我刚刚在新的Windows 7机器上安装了Node.js,结果如下:
> node -v
v0.12.0
> npm -v
2.5.1
I then did the above described procedure:
然后我做了上述程序:
> npm install -g npm
and it upgraded to v2.7.3. Except than doing npm -v
still gave 2.5.1.
它升级到v2.7.3。除了做npm -v仍然给2.5.1。
I went to the System configuration panel, advanced settings, environment variables. I saw a PATH variable specific to my user account, in addition to the global Path variable.
The former pointed to new npm: C:\Users\PhiLho\AppData\Roaming\npm
The latter includes the path to node: C:\PrgCmdLine\nodejs\
(Nowadays, I avoid to install stuff in Program Files and derivates. Avoiding spaces in paths, and noisy useless protections is saner...)
If I do which npm.cmd
(I have Unix utilities installed...), it points to the one in Node.
我去了系统配置面板,高级设置,环境变量。除了全局Path变量之外,我还看到了一个特定于我的用户帐户的PATH变量。前者指向新的npm:C:\ Users \ PhiLho \ AppData \ Roaming \ npm后者包括节点的路径:C:\ PrgCmdLine \ nodejs \(现在,我避免在程序文件和派生中安装东西。避免空格在路径中,嘈杂无用的保护是更安全的......)如果我做了哪个npm.cmd(我安装了Unix实用程序......),它指向Node中的那个。
Anyway, the fix is simple: I just copied the first path (to npm) just before the path to node in the main, global Path variable, and now it picks up the latest version.<some stuff before>;C:\Users\PhiLho\AppData\Roaming\npm;C:\PrgCmdLine\nodejs\
无论如何,修复很简单:我只是在主要的全局Path变量中的节点路径之前复制了第一个路径(到npm),现在它获取了最新版本。 <之前的一些东西> ; C:\ Users \ PhiLho \ AppData \ Roaming \ npm; C:\ PrgCmdLine \ nodejs \
> npm -v
2.7.3
Enjoy. :-)
#13
12
For Linux, OSX, etc..
适用于Linux,OSX等。
To install the latest version of NPM
安装最新版本的NPM
npm install -g npm@latest
npm install -g npm @ latest
Or To Install the most recent release
或者安装最新版本
npm install -g npm@next
npm install -g npm @ next
Additional : To check your npm version
附加:检查您的npm版本
npm -v
If you are in a Windows Machine, I suggest going to the npm website
如果你在Windows机器上,我建议你去npm网站
#14
11
Just run the following command in terminal as root/administrator:
只需在终端中以root / administrator身份运行以下命令:
npm i -g n
n stable
npm update -g npm
It has worked for me on Linux
它在Linux上对我有用
#15
10
Install npm => sudo apt-get install npm
安装npm => sudo apt-get install npm
Install n => sudo npm install n -g
安装n => sudo npm install n -g
latest version of node => sudo n latest
最新版本的node => sudo n latest
Specific version of node you can
您可以使用特定版本的节点
List available node versions => n ls
列出可用节点版本=> n ls
Install a specific version => sudo n 4.5.0
安装特定版本=> sudo n 4.5.0
#16
9
I recently stumbled across this article: http://martineau.tv/blog/2013/12/more-efficient-grunt-workflows/ and the author mentions $ npm-check-updates -u && npm install
to update all dependencies.
我最近偶然发现了这篇文章:http://martineau.tv/blog/2013/12/more-efficient-grunt-workflows/,作者提到$ npm-check-updates -u && npm install来更新所有依赖项。
This is a little off the topic but I ended up here on a similar search so thought it was worth the share.
这有点偏离主题,但我最终在这里进行了类似的搜索,所以认为值得分享。
#17
9
Sometimes it's just simpler to download the latest version from http://nodejs.org/
有时从http://nodejs.org/下载最新版本更简单
Especially when all other options fail.
特别是当所有其他选项都失败时
http://nodejs.org/ -> click INSTALL -> you'll have the latest node and npm
http://nodejs.org/ - >单击“安装” - >您将拥有最新节点和npm
Simple!
#18
9
Just listened to an interview with the npm team on the latest episode of nodeup, and they recommended not using update
for the update from 1.x
to 2.x
. Instead, use: npm install npm -g
刚刚收听了npm团队关于nodeup最新一集的采访,他们建议不要使用更新从1.x到2.x的更新。相反,使用:npm install npm -g
#19
8
Just with this code
只需使用此代码
npm install update
#20
8
To update npm :
要更新npm:
npm install npm@{version} -g
to update npm to the latest version:
将npm更新到最新版本:
npm install npm@latest -g
and to check the version :
并检查版本:
npm -v
to update node js :
更新节点js:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
to check :
去检查 :
node -v
#21
6
For Cygwin users:
对于Cygwin用户:
Installing n (node version manager) in Cygwin
doesn't work, instead update node with:
在Cygwin中安装n(节点版本管理器)不起作用,而是使用以下命令更新节点:
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\pathto\nodejs\node.exe'
# Updating npm
npm i -g npm
Yes, you need to install wget
first.
是的,你需要先安装wget。
#22
5
Also if you want to update to a particular version, follow this:
此外,如果您想要更新到特定版本,请按照下列步骤操作:
sudo npm cache clean -f
sudo npm install -g n
sudo n <specific version>
#23
5
for nodejs should uninstall it and download your favorite version from nodejs.org for npm run below line in cmd:
对于nodejs应该卸载它并从nodejs.org下载你喜欢的版本,以便在cmd下面的npm下运行:
npm i npm
#24
5
Try the latest stable version of npm
See what version of npm you're running:
npm -v
Upgrading on *nix (OSX, Linux, etc.)
(You may need to prefix these commands with sudo
, especially on Linux, or OS X if you installed Node using its default installer.)
(您可能需要在sudo前加上这些命令的前缀,特别是在Linux上,如果您使用默认安装程序安装了Node,则需要在OS X前加上前缀。)
You can upgrade to the latest version of npm using:
您可以使用以下命令升级到最新版本的npm:
npm install -g npm@latest
Or upgrade to the most recent release:
或者升级到最新版本:
npm install -g npm@next
Upgrading on Windows
By default, npm is installed alongside node in
默认情况下,npm与节点一起安装
C:\Program Files (x86)\nodejs
C:\ Program Files(x86)\ nodejs
npm's globally installed packages (including, potentially, npm itself) are stored separately in a user-specific directory (which is currently
npm的全局安装包(可能包括npm本身)分别存储在用户特定的目录中(目前是
C:\Users\<username>\AppData\Roaming\npm
).
Because the installer puts
因为安装程序放了
C:\Program Files (x86)\nodejs
C:\ Program Files(x86)\ nodejs
before
C:\Users\<username>\AppData\Roaming\npm
on your PATH
, it will always use the version of npm installed with node instead of the version of npm you installed using npm -g install npm@<version>
.
在你的PATH上,它将始终使用与节点一起安装的npm版本,而不是使用npm -g install npm @
To get around this, you can do one of the following:
要解决此问题,您可以执行以下操作之一:
-
Option 1: edit your Windows installation's
PATH
to put%appdata%\npm
before%ProgramFiles%\nodejs
. Remember that you'll need to restartcmd.exe
(and potentially restart Windows) when you make changes toPATH
or how npm is installed.选项1:编辑Windows安装的PATH,将%appdata%\ npm放在%ProgramFiles%\ nodejs之前。请记住,当您对PATH进行更改或如何安装npm时,您需要重新启动cmd.exe(并可能重新启动Windows)。
-
Option 2: remove both of
选项2:删除两者
%ProgramFiles%\nodejs\npm
%ProgramFiles%\nodejs\npm.cmd
-
Option 3: Navigate to
%ProgramFiles%\nodejs\node_modules\npm
and copy thenpmrc
file to another folder or the desktop. Then opencmd.exe
and run the following commands:选项3:导航到%ProgramFiles%\ nodejs \ node_modules \ npm并将npmrcfile复制到另一个文件夹或桌面。然后打开cmd.exe并运行以下命令:
If you installed npm with the node.js installer, after doing one of the previous steps, do the following.
如果使用node.js安装程序安装了npm,则在执行上述步骤之后,请执行以下操作。
-
Option 1 or 2
选项1或2
- Go into
%ProgramFiles%\nodejs\node_modules\npm
and copy the file namednpmrc
in the new npm folder, which should be%appdata%\npm\node_modules\npm
. This will tell the new npm where the global installed packages are.
进入%ProgramFiles%\ nodejs \ node_modules \ npm并在新的npm文件夹中复制名为npmrc的文件,该文件夹应为%appdata%\ npm \ node_modules \ npm。这将告诉新的npm全局安装包的位置。
- Go into
-
Option 3
- Copy the npmrc file back into
%ProgramFiles%\nodejs\node_modules\npm
将npmrc文件复制回%ProgramFiles%\ nodejs \ node_modules \ npm
- Copy the npmrc file back into
选项3将npmrc文件复制回%ProgramFiles%\ nodejs \ node_modules \ npm
A brief note on the built-in Windows configuration
The Node installer installs, directly into the npm folder, a special piece of Windows-specific configuration that tells npm where to install global packages. When npm is used to install itself, it is supposed to copy this special builtin
configuration into the new install. There was a bug in some versions of npm that kept this from working, so you may need to go in and fix that up by hand. Run the following command to see where npm will install global packages to verify it is correct.
Node安装程序直接在npm文件夹中安装一个特殊的Windows特定配置,告诉npm安装全局软件包的位置。当使用npm进行自我安装时,应该将此特殊内置配置复制到新安装中。某些版本的npm中存在一个错误,导致无法正常工作,因此您可能需要手动修复。运行以下命令以查看npm将在何处安装全局程序包以验证它是否正确。
npm config get prefix -g
If it isn't set to <X>:\Users\<user>\AppData\Roaming\npm
, you can run the below command to correct it:
如果未设置为
npm config set prefix "${APPDATA}/npm" -g
Incidentally, if you would prefer that packages not be installed to your roaming profile (because you have a quota on your shared network, or it makes logging in or out from a domain sluggish), you can put it in your local app data instead:
顺便提一下,如果您希望不将软件包安装到漫游配置文件中(因为您的共享网络上有配额,或者它使得从域缓慢登录或注销),您可以将其放在本地应用程序数据中:
npm config set prefix "${LOCALAPPDATA}/npm" -g
...as well as copying %APPDATA%\npm
to %LOCALAPPDATA%\npm
(and updating your %PATH%
, of course).
...以及将%APPDATA%\ npm复制到%LOCALAPPDATA%\ npm(当然还要更新%PATH%)。
Everyone who works on npm knows that this process is complicated and fraught, and we're working on making it simpler. Stay tuned.
在npm工作的每个人都知道这个过程很复杂,而且我们正在努力使它变得更简单。敬请关注。
Source: https://docs.npmjs.com/troubleshooting/try-the-latest-stable-version-of-npm
#25
4
Just run the below scripts on console:
只需在控制台上运行以下脚本:
sudo npm i -g n
sudo n stable
sudo npm update -g npm
This will work for Linux and MAC only
这仅适用于Linux和MAC
#26
4
Use n module from npm in order to upgrade node . n is a node helper package that installs or updates a given node.js version.
从npm使用n模块以升级节点。 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
NOTE that the default installation for nodejs is in the /usr/bin/nodejs and not /usr/bin/node
注意nodejs的默认安装位于/ usr / bin / nodejs而不是/ usr / bin / node
To upgrade to latest version (and not current stable) version, you can use
要升级到最新版本(而不是当前稳定版),您可以使用
sudo n latest
sudo n最新
To 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
If you get the following error bash: /usr/bin/node: No such file or directory
then the path you have entered at
如果你得到以下错误bash:/ usr / bin / node:没有这样的文件或目录,那么你输入的路径
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs
if wrong. so make sure to check if the update nodejs has been installed at the above path and the version you are entered is correct.
如果错了因此,请确保检查更新的nodejs是否已安装在上述路径中,并且输入的版本是否正确。
I would advise strongly against doing this on a production instance. It can seriously mess stuff up with your global npm packages and your ability to install new one.
我强烈建议不要在生产实例上这样做。它会严重影响您的全局npm软件包以及安装新软件包的能力。
#27
3
If you don't want to update to the latest version. Do this command:
如果您不想更新到最新版本。执行此命令:
npm install npm@4.2.0 -g
npm install npm@4.2.0 -g
Replace 4.2.0 with whatever version you want. Here are all the release versions by Oct 3rd 2017: https://nodejs.org/en/download/releases/
将4.2.0替换为您想要的任何版本。以下是2017年10月3日发布的所有版本:https://nodejs.org/zh/download/releases/
#28
3
Here is a simple fix for those who installed node
via Homebrew without npm
and later on struggled with npm
upgrade/installation using an official script. This approach assumes you have run the node
installation as follows:
这是一个简单的修复程序,适用于那些通过Homebrew安装节点而没有npm,后来又使用官方脚本进行npm升级/安装的人。此方法假定您已按如下方式运行节点安装:
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
If above failed then start from here. Remove npm
if any:
如果失败则从这里开始。删除npm如果有的话:
rm -rf ~/.npm-packages/lib/node_modules/npm
Download and unpack the latest version of npm
, currently at 5.6.0:
下载并解压缩最新版本的npm,目前为5.6.0:
cd ~
curl -L https://registry.npmjs.org/npm/-/npm-5.6.0.tgz | tar xz
Move unpacked package into node_modules folder:
将解压缩的包移动到node_modules文件夹中:
mv ~/package ~/.npm-packages/lib/node_modules/npm
Make sure your ~/.bash_profile
has following entries:
确保你的〜/ .bash_profile有以下条目:
export NPM_PACKAGES="$HOME/.npm-packages"
export NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
export PATH="$NPM_PACKAGES/bin:$PATH"
Source the file:
来源文件:
source ~/.bash_profile
Verify installation:
npm -v
#29
3
you should see this blog nodejs install with package-manager
你应该看看这个博客nodejs与package-manager一起安装
Before you performance this command. you show run sudo apt-get update
, make sure result is Reading package lists... Done, no ERROR
在执行此命令之前。你显示运行sudo apt-get update,确保结果是读取包列表...完成,没有错误
Step by Step (Debian):
一步一步(Debian):
sudo apt-get update
install 6_x
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
install 7_x
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
#30
2
If you're using Windows: Go to https://nodejs.org/en/download/, download latest .exe
or .msi
file and install to overwrite the old versions
如果您使用的是Windows:请访问https://nodejs.org/en/download/,下载最新的.exe或.msi文件并安装以覆盖旧版本
If you're using Ubuntu or Linux: Uninstall node.js
first then reinstall, e.g with Ubuntu ():
如果您正在使用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
Remove node_modules
in your project folder and npm install
to make sure your application will run well on new node
and npm
version.
删除项目文件夹中的node_modules和npm install,以确保您的应用程序在新节点和npm版本上运行良好。
#1
1419
See the docs for the update
command:
请参阅update命令的文档:
npm update [<name> [<name> ...]]
This command will update all the packages listed to the latest version (specified by the tag config). It will also install missing packages.
此命令将更新列出的最新版本的所有软件包(由标记配置指定)。它还将安装缺少的包。
Additionally, see the FAQ:
另外,请参阅常见问题:
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.请注意,此命令将删除当前版本的npm。如果在Mac上,请务必使用sudo npm install -g npm。
You can also update all outdated local packages by doing
npm update
without any arguments, or global packages by doingnpm update -g
.您还可以通过执行npm update而不使用任何参数来更新所有过时的本地程序包,或者通过执行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:
有时,npm的版本会进展,以至于无法使用已安装的版本正确安装当前版本。 (如果update命令中有错误,请考虑。)在这些情况下,您可以这样做:
curl https://www.npmjs.com/install.sh | sh
To update Node.js itself, I recommend you use nvm, the Node Version Manager.
要更新Node.js本身,我建议您使用节点版本管理器nvm。
#2
355
I found this really neat way of updating node on David Walsh's blog, you can do it by installing n
:
我在David Walsh的博客上发现了这种更新节点的方法,你可以通过安装n来实现:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
It will install the current stable version of node
. However, I recommend using nvm
.
它将安装当前稳定版本的节点。但是,我建议使用nvm。
#3
176
Updating npm is easy:
更新npm很简单:
npm install npm@latest -g
#4
127
I understand this question is for Linux machine but just in case anybody is looking for a Windows solution, just go to the Node.js site, click the download button on the homepage and execute the installer program.
我理解这个问题适用于Linux机器,但万一有人正在寻找Windows解决方案,只需转到Node.js站点,单击主页上的下载按钮并执行安装程序。
Thankfully it took care of everything and with a few clicks of 'Next' button I got the latest 0.8.15 Node.js version running on my Windows 7 machine.
值得庆幸的是,它完成了一切,只需点击几下“下一步”按钮,我就可以在Windows 7机器上运行最新的0.8.15 Node.js版本。
#5
101
As you may know, NPM is currently bundled with Node.js, it means that if you have installed node
you already have installed npm
. There are several approaches to keep up to date the Node.js and NPM, you need to use one of the following version managers:
您可能知道,NPM目前与Node.js捆绑在一起,这意味着如果您已经安装了节点,那么您已经安装了npm。有几种方法可以保持最新的Node.js和NPM,您需要使用以下版本管理器之一:
Homebrew
If yo are on Mac, you can use Homebrew. To install NodeJS and NPM using brew:
如果你在Mac上,你可以使用Homebrew。使用brew安装NodeJS和NPM:
$ brew install node
later you will be able to update it using
稍后您将能够使用更新它
$ brew update && brew upgrade node
NPM will be updated as well.
NPM也将更新。
You also will be able to switch
to the one of the previous versions if you need, for example:
如果需要,您还可以切换到以前的版本之一,例如:
$ brew switch node 0.10.26
To install brew to your Mac:
要将brew安装到Mac:
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
N
n is most likely to rvm
(Ruby Version Manager), and can be used to manage and update node/npm
versions.
n最有可能是rvm(Ruby Version Manager),可用于管理和更新node / npm版本。
Install Node.js versions easily:
轻松安装Node.js版本:
$ n 0.10.26
$ n 0.8.17
$ n 0.9.6
Use (and install if missing) the latest official release:
使用(如果缺少则安装)最新的官方发布:
$ n latest
Use/install the stable official release:
使用/安装稳定的官方发布:
$ n stable
Switch to the previous version you were using:
切换到您使用的先前版本:
$ n prev
If you want to see the list of installed nodes, just run n
from your command line, the output will be something like the following:
如果要查看已安装节点的列表,只需从命令行运行n,输出将如下所示:
$ n
0.10.26
• 0.8.17
0.9.6
The dot (•) means that it's a currently active version. To select a node version from the list use up
and down
arrows and activate using enter
.
点(•)表示它是当前活动的版本。要从列表中选择节点版本,请使用向上和向下箭头并使用enter激活。
The n
package is written on pure linux shell
and available as a npm module (contains package.json
), so if you have any Node.js installed, you can install/update the n
through the npm
:
n包是在纯linux shell上编写的,可以作为npm模块(包含package.json)使用,所以如果你安装了任何Node.js,你可以通过npm安装/更新n:
$ npm install -g n
NVM
nvm is also like RVM
, even the command names and usage are very similar.
nvm也像RVM一样,甚至命令名和用法都非常相似。
To download, compile, and install the latest v0.10.x release of the Node.js using nvm
:
使用nvm下载,编译和安装Node.js的最新v0.10.x版本:
$ nvm install 0.10
And then you can switch to the installed version:
然后您可以切换到已安装的版本:
$ nvm use 0.10
You can create an .nvmrc
file containing version number in the project root folder; then run the following command to switch to the specified version:
您可以在项目根文件夹中创建包含版本号的.nvmrc文件;然后运行以下命令切换到指定的版本:
$ nvm use
Or you can just run it:
或者你可以运行它:
$ nvm run 0.10
If you want to see which versions are already installed, use:
如果要查看已安装的版本,请使用:
$ nvm ls
To install nvm
itself you can use the install script (requires git
) using cURL
:
要安装nvm本身,您可以使用cURL使用安装脚本(需要git):
$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh
or wget
:
$ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
P.S.
All these approaches I've used on MacOSX and Linux, I don't have any experience on how to manage Node.js versions on Windows, I can only suppose that the n
(the second one) will work for Microsoft's OS (at least from the cygwin
).
我在MacOSX和Linux上使用的所有这些方法,我没有任何关于如何在Windows上管理Node.js版本的经验,我只能假设n(第二个)将适用于Microsoft的操作系统(至少来自cygwin)。
#6
86
First check your NPM version
npm -v
1) Update NPM to current version:
View curent NPM version:
查看curent NPM版本:
npm view npm version
Update npm to current version:
将npm更新为当前版本:
npm i -g npm
2) List all available NPM versions and make a custom install/update/roll-back
View all versions including "alpha", "beta" and "rc" (release candidate)
查看所有版本,包括“alpha”,“beta”和“rc”(发布候选版)
npm view npm versions --json
Reinstall NPM to a specific version chosen from the versions list - for example to 5.0.3
将NPM重新安装到从版本列表中选择的特定版本 - 例如5.0.3
npm i -g npm@5.0.3
-
Installing one version will automatically remove the one currently installed.
安装一个版本将自动删除当前安装的版本。
-
For Linux and iOS prepend commands with sudo
对于Linux和iOS,使用sudo前置命令
#7
49
Upgrading for Windows Users
Windows users should read Troubleshooting > Upgrading on Windows in the npm wiki.
Windows用户应阅读npm wiki中的“故障排除”>“在Windows上升级”。
Upgrading on windows 10 using PowerShell (3rd party edit)
The link above Troubleshooting#upgrading-on-windows points to a github page npm-windows-upgrade the lines below are quotes from the readme. I successfully upgraded from npm 2.7.4 to npm 3.9.3 using node v5.7.0 and powershell (presumably powershell version 5.0.10586.122)
故障排除#regrade-on-windows上面的链接指向github页面npm-windows-upgrade下面的行是自述文件中的引号。我使用node v5.7.0和powershell(大概是powershell版本5.0.10586.122)成功地从npm 2.7.4升级到npm 3.9.3
First, ensure that you can execute scripts on your system by running the following command from an elevated PowerShell. To run PowerShell as Administrator, click Start, search for PowerShell, right-click PowerShell and select Run as Administrator.
首先,通过从提升的PowerShell运行以下命令,确保您可以在系统上执行脚本。要以管理员身份运行PowerShell,请单击“开始”,搜索PowerShell,右键单击“PowerShell”,然后选择“以管理员身份运行”。
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
Then, to install and use this upgrader tool, run (also from an elevated PowerShell or cmd.exe):
然后,要安装并使用此升级工具,请运行(也可以从提升的PowerShell或cmd.exe):
npm install --global --production npm-windows-upgrade
npm-windows-upgrade
#8
45
First update npm
,
第一次更新npm,
npm install -g npm@next
npm install -g npm @ next
Then update node
to the next version,
然后将节点更新到下一个版本,
npm install -g node@next
or npm install -g n@next
or, to the latest,
npm install -g node @ next或npm install -g n @ next或者到最新的,
npm install -g node@latest
or npm install -g node
npm install -g node @ latest或npm install -g node
check after version installation,
版本安装后检查,
node --version
or node -v
node --versionor node -v
#9
40
SIMPLY USE THIS
npm i -g npm
This is what i get promped on my console from npm when new update/bug-fix are released:
这是我在我的控制台上从npm发布新的更新/错误修复时提示的内容:
#10
25
-
To update node use nvm (or nvmw for windows).
要更新节点,请使用nvm(或nvmw for windows)。
-
To update npm, the
npm update npm -g
command didn't work for me (on windows). What did work was reinstalling npm according to the documentation: "You can download a zip file from https://npmjs.org/dist/, and unpack it in the same folder where node.exe lives." Make sure if you do this that you get rid of your previous installation first (though overwriting it will probably work ok...).要更新npm,npm update npm -g命令对我不起作用(在Windows上)。根据文档重新安装npm的工作是什么:“你可以从https://npmjs.org/dist/下载一个zip文件,然后将它解压缩到node.exe所在的同一个文件夹中。”确保如果你这样做,你先摆脱以前的安装(虽然覆盖它可能会正常工作......)。
-
To update your modules, use the npm update command
要更新模块,请使用npm update命令
#11
17
$ npm install -g npm stable
Worked for me to update from 1.4.28 to 2.1.5
我的工作是从1.4.28更新到2.1.5
#12
14
I just installed Node.js on a new Windows 7 machine, with the following results:
我刚刚在新的Windows 7机器上安装了Node.js,结果如下:
> node -v
v0.12.0
> npm -v
2.5.1
I then did the above described procedure:
然后我做了上述程序:
> npm install -g npm
and it upgraded to v2.7.3. Except than doing npm -v
still gave 2.5.1.
它升级到v2.7.3。除了做npm -v仍然给2.5.1。
I went to the System configuration panel, advanced settings, environment variables. I saw a PATH variable specific to my user account, in addition to the global Path variable.
The former pointed to new npm: C:\Users\PhiLho\AppData\Roaming\npm
The latter includes the path to node: C:\PrgCmdLine\nodejs\
(Nowadays, I avoid to install stuff in Program Files and derivates. Avoiding spaces in paths, and noisy useless protections is saner...)
If I do which npm.cmd
(I have Unix utilities installed...), it points to the one in Node.
我去了系统配置面板,高级设置,环境变量。除了全局Path变量之外,我还看到了一个特定于我的用户帐户的PATH变量。前者指向新的npm:C:\ Users \ PhiLho \ AppData \ Roaming \ npm后者包括节点的路径:C:\ PrgCmdLine \ nodejs \(现在,我避免在程序文件和派生中安装东西。避免空格在路径中,嘈杂无用的保护是更安全的......)如果我做了哪个npm.cmd(我安装了Unix实用程序......),它指向Node中的那个。
Anyway, the fix is simple: I just copied the first path (to npm) just before the path to node in the main, global Path variable, and now it picks up the latest version.<some stuff before>;C:\Users\PhiLho\AppData\Roaming\npm;C:\PrgCmdLine\nodejs\
无论如何,修复很简单:我只是在主要的全局Path变量中的节点路径之前复制了第一个路径(到npm),现在它获取了最新版本。 <之前的一些东西> ; C:\ Users \ PhiLho \ AppData \ Roaming \ npm; C:\ PrgCmdLine \ nodejs \
> npm -v
2.7.3
Enjoy. :-)
#13
12
For Linux, OSX, etc..
适用于Linux,OSX等。
To install the latest version of NPM
安装最新版本的NPM
npm install -g npm@latest
npm install -g npm @ latest
Or To Install the most recent release
或者安装最新版本
npm install -g npm@next
npm install -g npm @ next
Additional : To check your npm version
附加:检查您的npm版本
npm -v
If you are in a Windows Machine, I suggest going to the npm website
如果你在Windows机器上,我建议你去npm网站
#14
11
Just run the following command in terminal as root/administrator:
只需在终端中以root / administrator身份运行以下命令:
npm i -g n
n stable
npm update -g npm
It has worked for me on Linux
它在Linux上对我有用
#15
10
Install npm => sudo apt-get install npm
安装npm => sudo apt-get install npm
Install n => sudo npm install n -g
安装n => sudo npm install n -g
latest version of node => sudo n latest
最新版本的node => sudo n latest
Specific version of node you can
您可以使用特定版本的节点
List available node versions => n ls
列出可用节点版本=> n ls
Install a specific version => sudo n 4.5.0
安装特定版本=> sudo n 4.5.0
#16
9
I recently stumbled across this article: http://martineau.tv/blog/2013/12/more-efficient-grunt-workflows/ and the author mentions $ npm-check-updates -u && npm install
to update all dependencies.
我最近偶然发现了这篇文章:http://martineau.tv/blog/2013/12/more-efficient-grunt-workflows/,作者提到$ npm-check-updates -u && npm install来更新所有依赖项。
This is a little off the topic but I ended up here on a similar search so thought it was worth the share.
这有点偏离主题,但我最终在这里进行了类似的搜索,所以认为值得分享。
#17
9
Sometimes it's just simpler to download the latest version from http://nodejs.org/
有时从http://nodejs.org/下载最新版本更简单
Especially when all other options fail.
特别是当所有其他选项都失败时
http://nodejs.org/ -> click INSTALL -> you'll have the latest node and npm
http://nodejs.org/ - >单击“安装” - >您将拥有最新节点和npm
Simple!
#18
9
Just listened to an interview with the npm team on the latest episode of nodeup, and they recommended not using update
for the update from 1.x
to 2.x
. Instead, use: npm install npm -g
刚刚收听了npm团队关于nodeup最新一集的采访,他们建议不要使用更新从1.x到2.x的更新。相反,使用:npm install npm -g
#19
8
Just with this code
只需使用此代码
npm install update
#20
8
To update npm :
要更新npm:
npm install npm@{version} -g
to update npm to the latest version:
将npm更新到最新版本:
npm install npm@latest -g
and to check the version :
并检查版本:
npm -v
to update node js :
更新节点js:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
to check :
去检查 :
node -v
#21
6
For Cygwin users:
对于Cygwin用户:
Installing n (node version manager) in Cygwin
doesn't work, instead update node with:
在Cygwin中安装n(节点版本管理器)不起作用,而是使用以下命令更新节点:
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\pathto\nodejs\node.exe'
# Updating npm
npm i -g npm
Yes, you need to install wget
first.
是的,你需要先安装wget。
#22
5
Also if you want to update to a particular version, follow this:
此外,如果您想要更新到特定版本,请按照下列步骤操作:
sudo npm cache clean -f
sudo npm install -g n
sudo n <specific version>
#23
5
for nodejs should uninstall it and download your favorite version from nodejs.org for npm run below line in cmd:
对于nodejs应该卸载它并从nodejs.org下载你喜欢的版本,以便在cmd下面的npm下运行:
npm i npm
#24
5
Try the latest stable version of npm
See what version of npm you're running:
npm -v
Upgrading on *nix (OSX, Linux, etc.)
(You may need to prefix these commands with sudo
, especially on Linux, or OS X if you installed Node using its default installer.)
(您可能需要在sudo前加上这些命令的前缀,特别是在Linux上,如果您使用默认安装程序安装了Node,则需要在OS X前加上前缀。)
You can upgrade to the latest version of npm using:
您可以使用以下命令升级到最新版本的npm:
npm install -g npm@latest
Or upgrade to the most recent release:
或者升级到最新版本:
npm install -g npm@next
Upgrading on Windows
By default, npm is installed alongside node in
默认情况下,npm与节点一起安装
C:\Program Files (x86)\nodejs
C:\ Program Files(x86)\ nodejs
npm's globally installed packages (including, potentially, npm itself) are stored separately in a user-specific directory (which is currently
npm的全局安装包(可能包括npm本身)分别存储在用户特定的目录中(目前是
C:\Users\<username>\AppData\Roaming\npm
).
Because the installer puts
因为安装程序放了
C:\Program Files (x86)\nodejs
C:\ Program Files(x86)\ nodejs
before
C:\Users\<username>\AppData\Roaming\npm
on your PATH
, it will always use the version of npm installed with node instead of the version of npm you installed using npm -g install npm@<version>
.
在你的PATH上,它将始终使用与节点一起安装的npm版本,而不是使用npm -g install npm @
To get around this, you can do one of the following:
要解决此问题,您可以执行以下操作之一:
-
Option 1: edit your Windows installation's
PATH
to put%appdata%\npm
before%ProgramFiles%\nodejs
. Remember that you'll need to restartcmd.exe
(and potentially restart Windows) when you make changes toPATH
or how npm is installed.选项1:编辑Windows安装的PATH,将%appdata%\ npm放在%ProgramFiles%\ nodejs之前。请记住,当您对PATH进行更改或如何安装npm时,您需要重新启动cmd.exe(并可能重新启动Windows)。
-
Option 2: remove both of
选项2:删除两者
%ProgramFiles%\nodejs\npm
%ProgramFiles%\nodejs\npm.cmd
-
Option 3: Navigate to
%ProgramFiles%\nodejs\node_modules\npm
and copy thenpmrc
file to another folder or the desktop. Then opencmd.exe
and run the following commands:选项3:导航到%ProgramFiles%\ nodejs \ node_modules \ npm并将npmrcfile复制到另一个文件夹或桌面。然后打开cmd.exe并运行以下命令:
If you installed npm with the node.js installer, after doing one of the previous steps, do the following.
如果使用node.js安装程序安装了npm,则在执行上述步骤之后,请执行以下操作。
-
Option 1 or 2
选项1或2
- Go into
%ProgramFiles%\nodejs\node_modules\npm
and copy the file namednpmrc
in the new npm folder, which should be%appdata%\npm\node_modules\npm
. This will tell the new npm where the global installed packages are.
进入%ProgramFiles%\ nodejs \ node_modules \ npm并在新的npm文件夹中复制名为npmrc的文件,该文件夹应为%appdata%\ npm \ node_modules \ npm。这将告诉新的npm全局安装包的位置。
- Go into
-
Option 3
- Copy the npmrc file back into
%ProgramFiles%\nodejs\node_modules\npm
将npmrc文件复制回%ProgramFiles%\ nodejs \ node_modules \ npm
- Copy the npmrc file back into
选项3将npmrc文件复制回%ProgramFiles%\ nodejs \ node_modules \ npm
A brief note on the built-in Windows configuration
The Node installer installs, directly into the npm folder, a special piece of Windows-specific configuration that tells npm where to install global packages. When npm is used to install itself, it is supposed to copy this special builtin
configuration into the new install. There was a bug in some versions of npm that kept this from working, so you may need to go in and fix that up by hand. Run the following command to see where npm will install global packages to verify it is correct.
Node安装程序直接在npm文件夹中安装一个特殊的Windows特定配置,告诉npm安装全局软件包的位置。当使用npm进行自我安装时,应该将此特殊内置配置复制到新安装中。某些版本的npm中存在一个错误,导致无法正常工作,因此您可能需要手动修复。运行以下命令以查看npm将在何处安装全局程序包以验证它是否正确。
npm config get prefix -g
If it isn't set to <X>:\Users\<user>\AppData\Roaming\npm
, you can run the below command to correct it:
如果未设置为
npm config set prefix "${APPDATA}/npm" -g
Incidentally, if you would prefer that packages not be installed to your roaming profile (because you have a quota on your shared network, or it makes logging in or out from a domain sluggish), you can put it in your local app data instead:
顺便提一下,如果您希望不将软件包安装到漫游配置文件中(因为您的共享网络上有配额,或者它使得从域缓慢登录或注销),您可以将其放在本地应用程序数据中:
npm config set prefix "${LOCALAPPDATA}/npm" -g
...as well as copying %APPDATA%\npm
to %LOCALAPPDATA%\npm
(and updating your %PATH%
, of course).
...以及将%APPDATA%\ npm复制到%LOCALAPPDATA%\ npm(当然还要更新%PATH%)。
Everyone who works on npm knows that this process is complicated and fraught, and we're working on making it simpler. Stay tuned.
在npm工作的每个人都知道这个过程很复杂,而且我们正在努力使它变得更简单。敬请关注。
Source: https://docs.npmjs.com/troubleshooting/try-the-latest-stable-version-of-npm
#25
4
Just run the below scripts on console:
只需在控制台上运行以下脚本:
sudo npm i -g n
sudo n stable
sudo npm update -g npm
This will work for Linux and MAC only
这仅适用于Linux和MAC
#26
4
Use n module from npm in order to upgrade node . n is a node helper package that installs or updates a given node.js version.
从npm使用n模块以升级节点。 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
NOTE that the default installation for nodejs is in the /usr/bin/nodejs and not /usr/bin/node
注意nodejs的默认安装位于/ usr / bin / nodejs而不是/ usr / bin / node
To upgrade to latest version (and not current stable) version, you can use
要升级到最新版本(而不是当前稳定版),您可以使用
sudo n latest
sudo n最新
To 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
If you get the following error bash: /usr/bin/node: No such file or directory
then the path you have entered at
如果你得到以下错误bash:/ usr / bin / node:没有这样的文件或目录,那么你输入的路径
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs
if wrong. so make sure to check if the update nodejs has been installed at the above path and the version you are entered is correct.
如果错了因此,请确保检查更新的nodejs是否已安装在上述路径中,并且输入的版本是否正确。
I would advise strongly against doing this on a production instance. It can seriously mess stuff up with your global npm packages and your ability to install new one.
我强烈建议不要在生产实例上这样做。它会严重影响您的全局npm软件包以及安装新软件包的能力。
#27
3
If you don't want to update to the latest version. Do this command:
如果您不想更新到最新版本。执行此命令:
npm install npm@4.2.0 -g
npm install npm@4.2.0 -g
Replace 4.2.0 with whatever version you want. Here are all the release versions by Oct 3rd 2017: https://nodejs.org/en/download/releases/
将4.2.0替换为您想要的任何版本。以下是2017年10月3日发布的所有版本:https://nodejs.org/zh/download/releases/
#28
3
Here is a simple fix for those who installed node
via Homebrew without npm
and later on struggled with npm
upgrade/installation using an official script. This approach assumes you have run the node
installation as follows:
这是一个简单的修复程序,适用于那些通过Homebrew安装节点而没有npm,后来又使用官方脚本进行npm升级/安装的人。此方法假定您已按如下方式运行节点安装:
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
If above failed then start from here. Remove npm
if any:
如果失败则从这里开始。删除npm如果有的话:
rm -rf ~/.npm-packages/lib/node_modules/npm
Download and unpack the latest version of npm
, currently at 5.6.0:
下载并解压缩最新版本的npm,目前为5.6.0:
cd ~
curl -L https://registry.npmjs.org/npm/-/npm-5.6.0.tgz | tar xz
Move unpacked package into node_modules folder:
将解压缩的包移动到node_modules文件夹中:
mv ~/package ~/.npm-packages/lib/node_modules/npm
Make sure your ~/.bash_profile
has following entries:
确保你的〜/ .bash_profile有以下条目:
export NPM_PACKAGES="$HOME/.npm-packages"
export NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
export PATH="$NPM_PACKAGES/bin:$PATH"
Source the file:
来源文件:
source ~/.bash_profile
Verify installation:
npm -v
#29
3
you should see this blog nodejs install with package-manager
你应该看看这个博客nodejs与package-manager一起安装
Before you performance this command. you show run sudo apt-get update
, make sure result is Reading package lists... Done, no ERROR
在执行此命令之前。你显示运行sudo apt-get update,确保结果是读取包列表...完成,没有错误
Step by Step (Debian):
一步一步(Debian):
sudo apt-get update
install 6_x
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
install 7_x
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
#30
2
If you're using Windows: Go to https://nodejs.org/en/download/, download latest .exe
or .msi
file and install to overwrite the old versions
如果您使用的是Windows:请访问https://nodejs.org/en/download/,下载最新的.exe或.msi文件并安装以覆盖旧版本
If you're using Ubuntu or Linux: Uninstall node.js
first then reinstall, e.g with Ubuntu ():
如果您正在使用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
Remove node_modules
in your project folder and npm install
to make sure your application will run well on new node
and npm
version.
删除项目文件夹中的node_modules和npm install,以确保您的应用程序在新节点和npm版本上运行良好。