Reputation: 22481
I just installed Node.js and npm
. I installed npm
for access to additional Node.js modules. After I installed Node.js and npm
, I noticed that neither were the latest versions available.
npm
and my Node.js modules to their latest versions?npm
, and reinstall the latest versions?Upvotes: 2226
Views: 2540736
Reputation: 111970
npm
Use the following command:
npm update -g npm
See the documentation for the update
command:
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 it 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 doingnpm 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
(Node Version Manager). Here is the quote from the official npm
documentation:
We strongly recommend using a Node version manager like
nvm
to install Node.js andnpm
. We do not recommend using a Node installer, since the Node installation process installsnpm
in a directory with local permissions and can cause permissions errors when you runnpm
packages globally.
Here is how you can do it using nvm
tool:
To install the latest release of Node, do this:
nvm install node
(NOTE: here node
is an alias for the latest version)
To install a specific version of node:
nvm install 22.2.0
More details can be found on the official nvm
GitHub page in the "Usage" section.
Upvotes: 2222
Reputation: 430
To update NodeJS on a Windows machine you should use 'fnm' which is recommended by the NodeJS site (https://nodejs.org/en/download/package-manager). (unless you are using chocolately on Windows, then you can also use this - instructions also on the link above.)
I found this useful, looking to update my Nodejs in the terminal on a windows in 2024, and thought I would add to the dicussion as this thread popped up at the top of google.
[The following is from the nodejs site - installing fnm for windows]
# installs fnm (Fast Node Manager)
winget install Schniz.fnm
# configure fnm environment
fnm env --use-on-cd | Out-String | Invoke-Expression
# download and install Node.js
fnm use --install-if-missing 20
# verifies the right Node.js version is in the environment
node -v # should print `v20.16.0`
# verifies the right npm version is in the environment
npm -v # should print `10.8.1`
This will update NodeJS and NPM to their latest versions very quickly on Windows.
Upvotes: 0
Reputation: 5791
I found this really neat way of updating Node.js on David Walsh's blog. You can do it by installing n
:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
It will install the current stable version of Node.js.
But please don't use n
anymore. I recommend using nvm
. You can simply install stable by following the commands below:
nvm ls-remote
nvm install <version>
nvm use <version>
Upvotes: 533
Reputation: 199
Use these commands to upgrade your node and npm to the latest version
First, uninstall the npm
npm uninstall -g npm
then clear the npm cache
npm cache clean --force
then install it again
npm install -g npm@latest
Hope it works!
Upvotes: 0
Reputation: 223
Steps to follow to update node
and/or npm
if you have them already installed on windows:
node -v
commandnode -v
npm install -g npm@latest
(for stable version) or npm install -g npm@next
(for recent version)npm -v
NOTE: If node version is lower than 18.17.0, step 5 will throw error on windows.
Upvotes: 2
Reputation: 6094
As you may already know, npm is currently bundled with Node.js. It means that if you have installed Node.js, you've already installed npm as well.
Also, pay attention to the Node.js and npm release versions table that shows us approximate versions compatibility. Sometimes, versions discrepancy may cause incompatibility errors.
So, if you're a developer, it's kind of "best practice" to manage your development environment using one of the Node.js version managers.
Here is a list and usage notes of some of the most popular:
If you're on macOS, you can use Homebrew.
Actually, it's not just a Node.js version manager.
To install Homebrew to your Mac:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
To install Node.js and npm using Homebrew, run:
brew install node
Later, you will be able to update them using:
brew update && brew upgrade node
Also, you can switch between Node.js versions as well:
brew switch node 0.10.26
npm will be upgraded/downgraded automatically.
n is most likely to rvm (Ruby Version Manager), and is used to manage Node.js and npm versions simultaneously. It is written on pure Linux shell, and available as an npm module. So, if you already have any Node.js version installed, you can install/update the n package through npm:
npm install -g n
Downloading, installing and switching to Node.js and npm versions is as easy as:
n 0.10.26
n 0.8.17
n 0.9.6
To download, install, and switch to the latest official release, use:
n latest
To download, install, and switch to the latest stable official release, use:
n stable
To switch to the previously active version (aka $ cd -
), use:
n prev
If you want to see the list of installed Node.js versions, just run n
from your command line. The output will be something like the following:
n
Output:
0.10.26
• 0.8.17
0.9.6
Where the dot (•) means that it's a currently active version. To select another Node.js version from the list, use Up/Down arrow keys and activate using the Enter key.
To list the versions available to install:
n lsr
nvm is also like rvm, even the command names and usage are very similar.
To install nvm, you can use the installation script (requires Git) using cURL
:
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
To download and install a specific Node.js and npm version, use:
nvm install 0.10
Then, you can switch to the installed version, using:
nvm use 0.10
Also, you can create the .nvmrc file containing the version number, then switch to the specified version using the following command:
nvm use
To see the list of installed Node.js versions, use:
nvm ls
To list the versions available to install:
nvm ls-remote
nvm-windows is a Node.js version management utility for Windows, ironically written in Go.
It is not the same thing as nvm. However, the usage as a Node.js version manager is very similar.
To install nvm-windows, it is required to uninstall any existing versions of Node.js and npm beforehand. Then, download and run the latest installer from releases.
To upgrade nvm-windows, run the new installer. It will safely overwrite the files it needs to update without touching your Node.js installations.
nvm-windows runs in an Admin shell. You'll need to start PowerShell or Command Prompt as Administrator to use nvm-windows.
Before using, you may also need to enable nvm-windows with the following command:
nvm on
To download and install a specific Node.js and npm version, use:
nvm install 0.12
Then, you can switch to the installed version, using:
nvm use 0.12
If you want to see the list of installed Node.js versions, use:
nvm list
To list the versions available to install:
nvm list available
Upvotes: 182
Reputation: 7180
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.
Upvotes: 14
Reputation: 60975
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...).
To update your modules, use the npm update command
Upvotes: 33
Reputation: 15753
I understand this question is for a 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.
Thankfully, it took care of everything, and with a few clicks of the Next button, I got the latest 0.8.15 Node.js version running on my Windows 7 machine.
Upvotes: 190
Reputation: 707
Don't worry about the current node version which is installed already. Just download and install the latest version from https://nodejs.org/en and run the installation wizard. (Note: The installation takes care of removing the existing node version and updates to the latest! )
You can verify the updated version by running:
node -v
To upgrade npm to the latest version on Windows, you can use the following command in the Command Prompt or PowerShell:
npm install -g npm@latest
After running the command, npm will download and install the latest version. Once the installation is complete, you can verify the updated version by running:
npm --version
Upvotes: 2
Reputation: 47
Update node latest version with this command:
nvm install <version>
Upvotes: 0
Reputation: 86
Every time I install a new Linux OS, I need to install the nodejs
and npm
, and sometimes the stable distros installs an old version of these..
So, here are the steps to upgrade to the latest stable one...
$ sudo npm install -g n
$ sudo n stable # this is for stable one
$ sudo n latest # this is for latest one
Hope this will help :)
Upvotes: 3
Reputation: 478
If you use linux you can use nvm to to manage multiple node versions in you projects
NVM allow you to install and use different versions in your project simple by:
nvm install YOUR_VERSION
to install your versionnvm use YOUR_VERSION
in your project to the version in the project also you can use .nvmrc
file to manage automatically the version in your projectsTo install Nvm you can use the official documentation Or by executing the next commands
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Now you are ready to use nvm....
Upvotes: 0
Reputation: 138
For windows
After installed the Node.js v16.15.1
npm -v is still 6.6.0
delete npm and npm-cache under C:\Users\neals\AppData\Roaming
npm -v is 8.11.0
Upvotes: 1
Reputation: 20118
We can update specific version of npm in the following way
npm install -g [email protected]
Upvotes: 0
Reputation:
You can upgrade to the latest version of npm using:
npm install -g npm@latest
Upvotes: 13
Reputation: 53
my advice is to use nvm (node version manager) which will allow you to install several versions of node and npm at the same time and will facilitate updates of node to LTS versions but also on Linux nvm overlay all npm command to avoid typing sudo for packages requiring superuser privileges. This is the link to see more about how nvm works.
Upvotes: 1
Reputation: 37974
Any OS (including Windows, Mac & Linux)
Updated May 2021
Just go to the official Node.js site (nodejs.org), download and execute the installer program.
It will take care of everything and with a few clicks of 'Next' you'll get the latest Node.js version running on your machine. Since 2020 it's the recommended way to update NodeJS. It's the easiest and least frustrating solution.
Pro tips
NodeJS installation includes NPM (Node package manager).
To check your NPM version use npm version
or node --version
.
If you prefer CLI, to update NPM use npm install -g npm
and then npm install -g node
.
install
command.Keep an eye on NodeJS blog - Vulnerabilities so you don't miss important security releases. Keep your NodeJS up-to-date.
Operating systems supported by Node.js:
Troubleshooting for Windows:
If anyone gets file error 2502/2503 like myself during install, run the .msi via Administrator command prompt with command
msiexec /package [node msi]
If my answer is helpful, don't forget to upvote it
(here is the original answer by Anmol Saraf, upvote it too)
Upvotes: 4
Reputation: 838
I think the best way to manage node.js is to use NVM. NVM stands for Node Version Manager.
It's a must-have tool for node.js developers!
You can install NVM using the following command, open terminal and run any one of the following:-
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/nvm-sh//nvm/v0.39.0/install.sh | bash
After installing this it's recommended to close the current terminal and open a new one since NVM will be adding some environment variables so terminal needs to be restarted.
I'll list down some of the basic commands for using NVM.
nvm ls-remote
npm doctor
nvm install <version recommended by 'npm doctor' or 'nvm ls-remote'>
for example nvm install v14.18.1
nvm ls
nvm uninstall v10.15.1
npm
on the current node versionnvm install-latest-npm
npm
packages from one version to another instead of manually installing each one of them!Upvotes: 31
Reputation: 816
As per the docs:
OSX & Linux
npm install -g npm@latest
Windows (in Powershell):
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install --global --production npm-windows-upgrade
npm-windows-upgrade
Just download the installer from here: https://nodejs.org/en/
You can update NodeJS with NPM using npm install -g node
but it isn't recommended.
Upvotes: 7
Reputation: 542
Steps to Upgrade npm and node Latest versions
1)Start by updating the package repository with the command
sudo apt update
2)Install NVM using the curl command
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
3)Close and reopen the terminal for system to recognize the changes or run the command:
source ~/.bashrc
4)Then, verify if you have successfully installed NVM:
nvm --version
5)Before upgrading Node.js, check which version you have running on the system:
nvm ls-remote
v14.17.0 (LTS: Fermium) v14.17.1 (LTS: Fermium) v14.17.2 (LTS: Fermium) v14.17.3 (LTS: Fermium) v14.17.4 (LTS: Fermium) v14.17.5 (LTS: Fermium) v14.17.6 (LTS: Fermium) v14.18.0 (Latest LTS: Fermium)
6)To install the latest version, use the nvm command with the specific Node.js version: My Latest Version
nvm install [version.number]
nvm install [14.8.0]
Upvotes: 1
Reputation: 87
Use nvm if you want to learn more about
For windows,installation follow this step by step installtion
Upvotes: 1
Reputation: 1
If you are using the Windows operating system, please follow the instruction
npm install npm@latest
If you are using ubuntu, you may also use the below command in your terminal
sudo apt-get update
sudo apt-get upgrade
sudo npm install npm@latest
First, check your NPM version
npm -v
View current NPM version:
npm view npm version
Update npm to the current version:
npm i -g npm
Happy coding, enjoy your life! Further, if you have face any difficulties let me know.
Upvotes: 5
Reputation: 159
npm install -g npm@latest
The above code can be run in the terminal to update your node package manager if you have already installed npm. If you don't have npm you can use
sudo apt-get install npm
then you can update it by the above method
Upvotes: 7
Reputation: 1727
For those who want to upgrade npm on windows,
Open Powershell(as administrator) and execute following commands sequentially,
>Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
>npm install -g npm-windows-upgrade
>npm-windows-upgrade -p -v latest
Upvotes: 3
Reputation: 323
firstly, you check to latest version
npm -v
and then update npm through this cmd
npm install -g npm@latest (hit this command in your terminal)
and check to latest version now I defiantly sure you npm version upgrade
npm -v
and also you can download the latest version from this link here:-
and if you using linux then visit this stackoverflow question
Upvotes: 5
Reputation: 668
To Install nodejs version 12.x and latest npm version of Ubuntu 20 Latest version follow these steps to install using PPA COPY THE WHOLE COMMAND AND RUN
cd ~ && curl -sL https://deb.nodesource.com/setup_12.x -o && nodesource_setup.sh && sudo bash nodesource_setup.sh && sudo apt install nodejs && nodejs -v
source https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04
Upvotes: 2
Reputation: 161
sudo n list => show the list of installed versions sudo n stable => install latest stable version.
You can also use nvm to install latest version or change between different versions.
For latest npm version: npm install -g npm@latest
Upvotes: 1
Reputation: 621
sudo npm install npm@latest
I run this on Linux so I am not sure about other operating systems.
sudo apt-get update
sudo apt-get upgrade
This will tell the apt-get
package manager to update and upgrade all packages.
Upvotes: 17