Upgrading Node.js to the latest version
Asked Answered
P

40

1129

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).

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.

Powerless answered 9/4, 2012 at 16:2 Comment(1)
Possible duplicate of How do I update Node.js?Disqualify
D
1768

Ubuntu Linux/Mac

The module n makes version-management easy:

npm install n -g

For the latest stable version:

n stable

For the latest version:

n latest

Debian 10

Upgrade older versions of node and npm on Debian 10 as follows:

sudo su -c 'curl -sL https://deb.nodesource.com/setup_18.x | bash -'
sudo apt-get install nodejs -y
sudo apt update
sudo apt upgrade
sudo npm install -g [email protected]
node --version
npm --version

Note: Replace setup_18 with the latest long-term support release.

Windows

just reinstall node from the .msi in Windows from the node website.

Ducan answered 9/4, 2012 at 16:6 Comment(29)
Thanks for the answer. I installed it and the following message was shown: [email protected] ../node_modules/n. When I type "n 0.4.12" I get the message that the command wasn't found. Do I need to be in a specific folder to use "n"?Powerless
"npm install -g n" did it!Powerless
yeah, you are totally right -g for installing it globally. BTW, Isn't it awesome?Ducan
Is there any way to upgrade to the latest version using n, instead of specifying the version?Sloppy
sudo npm cache clean -f sudo npm install -g n sudo n stableSundsvall
Is there anything similar for Win?Wini
@Wini just reinstall node from the .msi in Windows from the node website. No need for nFlammable
@vsync see my comment above ^Flammable
I lack the rep to do this, but For the latest version: would better read Use n to install the latest stable node:Combat
Upgrading on Windows is so easy you don't even need to know these tricksDulci
Note that you may need to run npm config set registry http://registry.npmjs.org/Maccarone
AWFUL idea. Does not work on Windows, and ruins your installation on non-x86 systems. Please update your answer to at least reflect these warnings.Disinclination
I needed to run sudo npm cache clean -f before I got rid of some errors.Nutty
I have upgraded my node from v0.10.31 to v0.12.0 on Ubuntu 14.04. Works likes a charm.Weasner
For all those suggesting the MSI, that's not an alternative because it doesn't replicate the behavior of this plugin (making installing/switching easy). Also as nice as this plugin in is for those that can use it, it's not in the spirit of Node because it uses BASH and thus doesn't work on Windows and Windows IS a first-class citizen with Node.Mandie
I needed to run sudo ln -s /usr/bin/nodejs /usr/bin/node as the first command. Otherwise I was getting /usr/bin/env: node: No such file or directoryApish
OSX Yosemite, npm install n -g && n stable worked for me. No need for sudo if node was not previously installed with it.Nucleotide
This answer is out of date. The best way to install/upgrade nodejs is to use Node Version Manager here: github.com/creationix/nvm or read this answer belowVanward
It doesn't replace existing version, it has installed the new one to /usr/local/n/versions/node/7.8.0 If you don't add it to the path, use n use latest yourscript.js to launch your script with the installed version of nodeIvaivah
sudo su will simplify to run the command under administrative rightsSquamosal
In Linux, you have to create a softlink as well. refer the accepted answer here. askubuntu.com/questions/426750/…Honeycomb
When use command 'node -v' to check whether upgrade success, remember to open a new terminal, otherwise you will still see the old version displayed.Schmitz
I've tried this solution several times, and closed and reeopened the terminal and still have v6.11.3 which is ridiculously outdated. This solution doesn't come close to working for Centos 7.Stelle
i have also tried didn't worked after doing sudo n stable node latest version got downloaded but reopen the terminal and checked still the old versionMonochromatism
I suggest using the more up to date answer below (without using Sudo). NVM is far more developer friendly and your less likely to end up with permission issues.Atcliffe
Please remove sudo from sudo npm. It's not a good practice to use sudo with npm, so it shouldn't be incentivized (ref)Irritable
Using sudo with any npm command can lead to many problems. Once sudo is used, it'll always need to be used.Unusual
isn't it better to use nvm?Galvin
Is n some official or trustworthy solution or is it leftpad grade nodeism?Sustentacular
T
799

All Platforms (Mac, Linux & Windows) 2024

If you just need to upgrade your old version of Node.js to the latest one and don't need multiple versions, simply over-write your existing executable with the new one.

Download the Latest Node.js from nodejs.org/en/download

enter image description here

This Just Works! TM on all platforms and is the easiest/fastest method.
When you run node -v in your terminal you will see the the latest version.

Mac

If you originally installed Node.js using brew then run:

brew upgrade node

Managing Multiple Versions of Node.js:

If you need to run multiple versions of Node.js on your machine e.g. if you have an older project that targets a specific version on AWS Lambda, then NVM (Node Version Manger) is your friend!

Step 1 - Get NVM

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

If you're curious about the installation command read the source code
... its been reviewed by several node.js security experts

Step 2 - Install the Specific Version of Node.js you need

Once you've got NVM you can install a specific version of Node.js using the nvm command:

nvm install v20.11.0

Note: you may need to close & re-open your terminal window for nvm command to be available.

You should expect to see something like this in your terminal:

Now using node v20.11.0

You now have the latest Node.js on your machine.
And if you need to temporarily switch to a different/previous version, you can do it with a simple nvm command.

Note: avoid using sudo with Node/NPM as it violates the security principal of least privilege

NVM is considered "better" than N for managing multiple Node.js versions because the verbose commands mean it is much easier to keep track of what you are doing in your Terminal/SSH Log. It is used by the team at NPM the creators/custodians of the Node.js World!

Totaquine answered 24/9, 2012 at 18:44 Comment(25)
I need version 0.8 to install grunt-contrib and nvm seems to provide only up to 0.6. This seems to rule out nvm as an option for me.Luciana
Yeah, there's an issue for it on GitHub: github.com/creationix/nvm/issues/90Totaquine
I ended up building from source. But perhaps I will switch to nvm in the next release. Thanks nelsonicLuciana
None of them are supported in Windows. NVM suggests nvmw and nvm-windows that are "neither supported nor developed by" NVM and I havent testsed out yet. @Totaquine your answer is awesomeDentist
nvm installs into a user's home directory. So if you use another tool to manage node processes, such as pm2, then you need to specify the new name of the node process (nodejs vs node) in order to experience the version nvm sets (if going from v0.12.x to v4.x for example). This is because nvm links node to nodejs only under the installed user's profile.Vanward
I must say that I was unable to change nodejs version usinv n. Everything was running fine, no errors, but the version after n stable was still 5.3.0 even though it should be 6.0.0 at the time of writing. Anyway, installed nvm , installed 6.1.0 and everything works. I'm on root user, no sudo needed anyway.Gut
After installing nvm and using command nvm install v6.9.1, I got this Version 'v6.9.1' not found - try 'nvm ls-remote' to browse available versions. . Even after I use nvm ls-remote, I got N/A . Currently I have v6.3.0Hotien
Hi @AnkurShah please raise an issue on GitHub: github.com/creationix/nvm/issues (thanks!)Totaquine
Shouldn't tl;dr be at the top for all the people that don't readHyrax
Unfortunately, nvm doesn't support Fish shell. Just run bash and when you're done, go back to Fish (run exit)Ummersen
"=> You currently have modules installed globally with npm. These will no => longer be linked to the active version of Node when you install a new node => with nvm; and they may (depending on how you construct your $PATH) => override the binaries of modules installed with nvm:" WTF?? so it does not do dependency check? NVM needs to learn from RVMBattleax
@LuisFlores agree that NVM could learn from RVM. see: github.com/creationix/nvm/issues/1418Totaquine
I needed to run source ~/.nvm/nvm.sh to make nvm available for terminal.Kinna
just a heads up for those using something other than the bash shell. run the curl command with the shell you're using eg: {command} | zshThermaesthesia
I am wondering, why should i even search this in SO... Probably Node people could make better job. Tnx for solution.Capernaum
I still have to use sudo to install versions because it says mkdir: cannot create directory '/usr/local/nvm/alias': Permission deniedHawkshaw
@Hawkshaw sounds like you need to fix your permissions. see: github.com/nvm-sh/nvm/issues/1164#issuecomment-248749969 You should avoid using sudo (root access) wherever possible.Totaquine
It's work on ubuntu 18.04 I got the latest version with: nvm install v12.6Ray
Good answer but... why use a random developer's (creationix) script and not the official nvm installation: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bashHereditable
If you already have existing packages in a similar node version (ex: 12.7) try this nvm install 12.13 --reinstall-packages-from=12.7. This will prevent you from having to reinstall necessary global modules like yarn, Gatsby, etc.Psychographer
What does update mean? Does it mean v14 will replace my existing version or does it co-exist side-by-side? Do I have to update the path to the node executable? Is this method safe for upgrading an existing running application in production?Cherlynchernow
@OldGeezer with nvm you can run multiple Node.js versions side-by-side or set a global default version. Definitely checkout the docs for more detail: github.com/nvm-sh/nvm#system-version-of-nodeTotaquine
STEP 2: Incase you get the error: "command not found: nvm" Run: source ~/.nvm/nvm.shFastening
As far as the install script and version numbers concerns raised by @MiguelMunoz I used sudo port install nvm which did get me the latest. Rather than the issue with the version number, I wasn't happy having stuff on my mac without knowing later how it got there, which is what would happen with a curl | bash. Keep in mind nvm team does not support homebrew (and probably forgot to mention they do not support macport either): still worked fine though.Generalist
nvm works for this caseHipparchus
T
139

via npm:

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

and also you can specify a desired version:

n 0.8.21

In case it doesn't seem to work, the installation gives you a hint :

If "node --version" shows the old version then start a new shell, or reset the location hash with: hash -r (for bash, zsh, ash, dash, and ksh) [or] rehash (for csh and tcsh)

reference

Teheran answered 18/7, 2013 at 13:24 Comment(0)
G
70

All platforms (Windows, Mac & Linux)

Just go to nodejs.org and use the latest installer.

That's it folks. It used to be more complex and people used different kinds of packages and strategies to manage it. But things have changed for the better.

Gillman answered 17/3, 2017 at 20:14 Comment(8)
This worked - but first had to manually remove the existing binary. I copied into a backup location to be safe mv /opt/local/bin/node ~/tmp/Mckinnie
@gnB What kind of error did you get? I'll include it in the answer.Gillman
This came up while working with Firebase CLI, which requires the latest node install. I didn't get an error - but every time I tried to run the CLI command firebase deploy, it kept referencing the old version/install that had like 0.12.12 in it.. and so firebase kept giving me an error saying I need to upgrade. After I did the remove line (from my initial comment), then the correct 6.x version/install was detectedMckinnie
just downloaded newest version, install, went to command prompt typed node -v, saw change instantly.Exertion
Just adding for the less experienced ones, that after downloading the binary, there is a bit of installation process, as described here: medium.com/@tgmarinho/….Floriated
Not sure why, but . .bash_profile didn't update the PATH for me. Had to close out the terminal session and restart :/Transmission
For some use cases this works, but not all. I had an existing app I wanted to test first before using the latest node and npm. Using nvm allowed me to switch back and forth, but this approach wouldn't because it would put on the latest with no way back if it didn't work: different strokes for different folks.Generalist
So happy about this to be honest, life is lots easier for us windows cavemen now.Changsha
F
69

On Windows download latest "Windows Installer (.msi)" from https://nodejs.org/download/release/latest/ and install same directory , thats all...

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:

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
Frayne answered 31/10, 2014 at 2:26 Comment(2)
I have installed these versions of node and I have Windows 10 installed. I have installed express and jade globally but in my project npm install express not working. Do you have any solution?Amalburga
Now you should run npm cache verify not npm cache cleanSchechter
C
42

Following Upgrading Node.js to the latest version

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 the latest version

sudo n latest

If you need to do Undo then follow the 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.!

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

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 losing your entire machine. That's where you can use nvm to download, install, and use different versions of Node.js:

nvm install 4.0

At any given time you can switch to another with the use:

nvm use 0.12

Addition n13: In case 'sudo n stable' has errors, try this:

sudo -E env "PATH=$PATH" n stable
Coelom answered 9/3, 2017 at 8:50 Comment(3)
This fixed my problem. Apparently, after updating the node needs a linking to the newer versionScald
sudo n stable didn't work - it said 'cant find command n'. Solution to that from another SO posT: sudo -E env "PATH=$PATH" n stableLarch
Please don't run sudo npm/n! It will mess up your permissions for several global npm packages and cause trouble the next time one of them is updated. See recent solutions in this thread.Polyglot
D
25

Upgrading node.js to the latest version on Windows

  1. Install chocolatey if you haven't already: Installing Chocolatey

  2. From the command prompt, type

    cup nodejs

(which is equivalent to typing choco upgrade nodejs -- assumes you already have node installed)

NOTE: You may need to run cinst nodejs.install for chocolatey to register your existing installation. (thanks for the comment, @mikecheel)


Installing node.js on Windows

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:

cinst nodejs.install

Chocolatey Gallery Node JS (Install)


Installing a specific version of node on Windows with chocolatey

cinst nodejs.install -Version 0.10.26

Diverge answered 1/9, 2014 at 2:48 Comment(3)
I had to run choco install nodejs.install for it to see my existing installation.Glarus
Make sure to run command prompt as administrator. (choco will warn you)Winny
Whats funny is I had node v 6 installed but when I tried to run cup nodejs it told me i didn't have nodejs installed at all. It asked if i wanted to install and I selected yes. When I run node -v i get version 10.7.0 so all is well! Thanks!Winny
S
16

Install npm =>

sudo apt-get install npm

Install 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
Stroup answered 26/5, 2017 at 11:24 Comment(0)
P
15

For brew users on Mac OSX

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
Partizan answered 13/8, 2015 at 1:7 Comment(0)
W
10

I had node version v7.10.0 in Ubuntu

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

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
Walker answered 26/7, 2017 at 18:35 Comment(0)
M
10

sudo npm install n -g sudo n 0.12.2

or

sudo npm install -g n sudo n latest

or

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

These work well. But for UX term terminal node -v did not show latest version so I have closed and reopened new terminal. I found v10.1.0, output of node-v after installation by sudo n latest

Mannose answered 13/5, 2018 at 13:32 Comment(0)
T
8

Using brew and nvm on Mac OSX:

If you're not using nvm, first uninstall nodejs. Then install Homebrew if not already installed. Then install nvm and node:

brew install nvm
nvm ls-remote    # find the version you want
nvm install v7.10.0
nvm alias default v7.10.0    # set default node version on a shell

You can now easily switch node versions when needed.

Bonus: If you see a "tar: invalid option" error when using nvm, brew install gnu-tar and follow the instructions brew gives you to set your PATH.

Tampon answered 18/5, 2017 at 22:47 Comment(0)
T
7
brew upgrade node

will upgrade to the latest version of the node

Typesetter answered 19/6, 2016 at 5:34 Comment(0)
K
7

If you are using Linux .. Just do the following steps sudo -i sudo apt install curl curl -sL https://deb.nodesource.com/setup_10.x | sudo bash - sudo apt-get install -y nodejs you should have now the latest version

Kutaisi answered 15/4, 2019 at 9:57 Comment(1)
Simple but effective. Thanks.Crumb
L
6

my 2c:

I tried both with n and with nvm on Linux Ubuntu 12.04 LTS, in order to update node from v0.8.25 to v0.10.22.

The first one was successfully completed, but the command 'which node' resulted in the old v0.8.25.
The second one was successfully completed and the same command resulted in v.0.10.22.

Lefkowitz answered 19/11, 2013 at 9:8 Comment(0)
C
4

You don't need to worry about an upgrading process.

You can just install the newest version using the official documentation as if you didn't have it installed and it will work like a charm. > https://nodejs.org/en/download/package-manager/ ;)

Connie answered 19/8, 2016 at 11:23 Comment(1)
By far the simplest answer! Easy to forget that there is a perfectly good installer for Node that works just like any other (unless you're desperate to use a CLI).Rodney
I
4

It's very simple in the Windows OS.

You do not have to do any uninstallation of the old Node.js or npm or anything else.

Just go to nodejs.org.

And then look for the Downloads for Windows option and below that click on Current... Latest Feature tab and follow the automated instructions.

It will download the latest Node.js and npm for you and discarding the old one.

Ify answered 13/9, 2020 at 7:45 Comment(0)
L
3

Open the package.json file of the node.js project and replace the version number specified with * in the dependencies will fetch you the latest version.

Leitmotif answered 31/8, 2016 at 19:58 Comment(0)
C
2

If you are looking in linux..

npm update will not work mostly am not sure reason but following steps will help you to resolve issue...

Terminal process to upgrade node 4.x to 6.x.

 $ node -v
 v4.x

Check node path

$ which node
/usr/bin/node

Download latest(6.x) node files from [Download][1]

[1]: https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x64.tar.xz and unzip files keep in /opt/node-v6.9.2-linux-x64/.

Now unlink current node and link with latest as following

$ unlink /usr/bin/node
$ ln -s /opt/node-v6.9.2-linux-x64/bin/node node
$ node -v
$ v6.9.2
Crooks answered 16/12, 2016 at 15:17 Comment(0)
T
2

There is good explanation for linux users how to update node version step by step. P.S type instead of sudo n stable sudo n latest for receive latest node version.

If you receive following error

Error: Module version mismatch. Expected 48, got 46.

You have just rebuilt npm by the following command npm rebuild it should fix the problem.

Tremolite answered 4/1, 2017 at 13:27 Comment(0)
T
2

For Windows users, simply go to the node.js (nodejs.org) website and download the latest version (8.6.0 as of 09/29/2017). Follow the steps from the auto install window and you're good to go. I just did it and when I checked my latest version in webstorm, it was already there.

Trackman answered 29/9, 2017 at 17:50 Comment(1)
I'm unsure what this answer adds to the many already existing ones.Settlement
C
2

Re-install the latest version of nodejs by downloading the latest .msi version from nodejs website here, https://nodejs.org/en/download/

It worked for me in my windows machine.

Churr answered 3/12, 2017 at 7:44 Comment(0)
J
2

just try this on your terminal :

nvm install node --reinstall-packages-from=node

it should do the trick.

later, run node --version to check the version that you have.

Josephinejosephson answered 12/4, 2018 at 10:48 Comment(0)
M
2

In order to install the latest version of Node.js and npm, do the following:

nvm install --lts
Moyers answered 31/3, 2023 at 12:9 Comment(0)
F
1

After install nvm as @nelsonic describes, this is the easiest way to keep it upgraded:

"node" is a shortcut to the last version, so you can install the last version with:

nvm install node

And to always use the "node" version:

nvm alias default node

Finally to upgrade your node version and keep the installed packages:

nvm install node --reinstall-packages-from=node
Fulk answered 28/4, 2016 at 3:14 Comment(0)
C
1

For Windows

I had the same problem, I tried to reinstall and didn't worked for me.

Remove "C:\Program Files(x86)\nodejs" from your system enviorment PATH and thats it!

Clinandrium answered 4/11, 2016 at 18:52 Comment(1)
First make sure that you have npm installed 1. Run the following cmd curl -fsSL deb.nodesource.com/setup_16.x | sudo -E bash - 2. run below cmd sudo apt-get install -y nodejsBattleplane
R
1

I used https://chocolatey.org/install

  1. install chocolatey refering this https://chocolatey.org/install
  2. run in cmd

cup nodejs

That's all. NodeJs now updated to latest version

Roadbed answered 6/10, 2018 at 18:8 Comment(0)
B
1

I am installing node for angular setup in Ubuntu. I also struggled a little bit. Here is the solution to save your time.

  1. Run the following commands

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -

  1. then run below code

sudo apt-get install -y nodejs

It should work, but if still didn't work to you let me know.

Battleplane answered 11/11, 2022 at 12:7 Comment(0)
M
0

Just bundling node and npm updates to latest version into a single command for my ~/.bash_profile:

update-node(){
  sudo n latest;
  sudo npm install -g npm;
  node --version;
}

This assumes you've already installed "n" from Eldar Djafarov's answer. After saving this to your Bash profile, re-open the terminal and just type update-node and enter your sudo password:

λ update-node
Password:
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
+ [email protected]
updated 1 package in 7.232s
v8.2.1
Maxa answered 9/8, 2017 at 21:23 Comment(0)
A
0

just run command line npm install -g npm or sudo npm install -g npmto update it for mac user. That's it.

Allyl answered 28/5, 2018 at 1:52 Comment(0)
B
0

Windows 10

Open CMD in folder C:\Program Files\nodejs\node_modules and type npm i npm

Better answered 10/10, 2018 at 3:4 Comment(0)
A
0

For Ubuntu

Install the nvm (Node Version Manager) using the below command

To install or update nvm, one can use the install script using cURL:

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

or Wget:

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

check if nvm is already installed

nvm --version

To install or update node, run below command:

nvm install 10.14.1(the version of node one want to install)

To check the list of node version available to the system or currently running for the system, run the below command:

nvm list

It will list all the available node version present in the system

check the node version:

node -v

Alcina answered 4/12, 2018 at 7:36 Comment(0)
S
0

If there is an issue with sudo/root access, we can do:

npm install stable Or
npm install 10.15.0
Seaweed answered 25/4, 2019 at 6:52 Comment(0)
D
0

Just install Node.js using nvm. It will download the latest version of Node.js.

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

After executing the command, close your terminal and reopen then run this command to install Node.js latest version.

Run: nvm install v14.15.5

Now check by typing node -v.

Dystopia answered 11/3, 2021 at 8:49 Comment(0)
B
0

In Windows 10/11, in my Azure DevOps pipeline, I run these commands from a PowerShell script in my restore phase:

if (!(Test-Path "./$nodeInstaller")) {

    $message = "Downloading node $nodeVersion"
    Write-Output $message

    Invoke-WebRequest "https://nodejs.org/dist/$nodeVersion/$($nodeInstaller)" -OutFile "./$nodeInstaller"
}

# Display node install message
$message = "Installing node $nodeVersion"
Write-Output $message

# Execute MsiExec silently and wait for it to complete.
Start-Process MsiExec.exe -Wait -ArgumentList "/i $($nodeInstaller) /qn /L*v msilog.txt"

In my case, this was necessary for some of my build tools (Angular 13 CLI) as the container image I'm using only had an old version of node. These commands are helpful also in a build/restore pipeline since we can wait for the installation to complete and capture some logs in case of an install failure.

Bicapsular answered 10/12, 2021 at 16:45 Comment(0)
E
0

Install nvm and then:

  • Install latest lts version by running : nvm install --lts
  • Set default version to latest lts (replace the version with the lts version) : nvm alias default 20.10.0
Enslave answered 4/12, 2023 at 16:32 Comment(0)
V
0

To update your npm:

npm i -g n
N_PREFIX=$HOME/.local n latest

You should get something similar to:

installing : node-v21.6.2
     mkdir : /home/user/.local/n/versions/node/21.6.2
     fetch : https://nodejs.org/dist/v21.6.2/node-v21.6.2-linux-x64.tar.xz
   copying : node/21.6.2
 installed : v21.6.2 to /home/user/.local/bin/node
    active : v18.12.1 at /home/user/.nvm/versions/node/v18.12.1/bin/node

Then run:

nvm install 21.6.2

And confirm the installation with:

node -v

Output:

v21.6.2

And you're good :)

Via answered 14/2 at 17:56 Comment(0)
H
-1

If Node install script doesn't work for you (it didn't for me), here's the solution to update Node Js in Debian Jessie, taken from the reply from Thomas Ward at askubuntu.com (Thanks, buddy!).

1.- Create a new file: /etc/apt/sources.list.d/nodesource.list

You'll need to create this file with sudo, but when you create the file, put this inside it:

deb https://deb.nodesource.com/node_9.x jessie main
deb-src https://deb.nodesource.com/node_9.x jessie main

Then, save the file. (replace node_9.x with the desired version)

2.- Download the GPG Signing Key from Nodesource for the repository. Otherwise, you may get NO_PUBKEY errors with apt-get update:

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

3.- Manually run sudo apt-get update.

This refreshes the data from the nodesource repo so apt knows a newer version exists.

If you get a NO_PUBKEY GPG error, then go back to Step 2

4.- Check apt-cache policy nodejs output.

This is not done by the script, but you want to make sure you see an entry that says something like this in the output:

Version table:
 *** 9.2.0-1nodesource1 0
        500 https://deb.nodesource.com/node_9.x/ jessie/main amd64 Packages
        100 /var/lib/dpkg/status
     0.10.29~dfsg-2 0
        500 http://ftp.debian.org/debian/ jessie/main amd64 Packages

If you do not see entries like this, and only see 0.10.29, start over. Otherwise, proceed.

5.- Install the nodejs binary. Now that you have confirmed 9.x is available on your system, you can install it: sudo apt-get install nodejs

nodejs -v should now show v9.2 or similar on output (as long as it starts with v9. you're on version 9 then).

Harwilll answered 19/11, 2017 at 7:23 Comment(0)
A
-1

To upgrade Node.js to the latest version, you can follow these general steps:

Check Current Version: First, check the currently installed version of Node.js by running:

node -v

Choose Installation Method: Decide on the installation method. You can either use a package manager like npm or yarn, or you can download the Node.js installer directly from the Node.js website.

Using npm (Node Package Manager): Open your terminal or command prompt. Run the following command to update npm to the latest version (optional but recommended):

npm install -g npm@latest

Then, run the following command to upgrade Node.js:

npm install -g node@latest

Using Yarn:

If you're using Yarn, you can upgrade Node.js by running:

yarn global upgrade node

Direct Download:

Alternatively, you can visit the official Node.js website and download the latest installer for your operating system. Run the installer, and it should automatically replace the older version with the latest one.

Verify Installation: After the installation is complete, verify that Node.js has been upgraded successfully by running:

node -v

Check npm Version: You might also want to check the npm version by running:

npm -v

Update Global Packages (Optional): If you have global npm packages installed, you might want to update them to ensure compatibility with the new Node.js version. You can do this by running:

npm update -g

By following these steps, you should be able to upgrade Node.js to the latest version on your system. Remember to check compatibility with your existing projects and dependencies after the upgrade.

Ainu answered 12/3 at 7:18 Comment(1)
stackoverflow.com/help/ai-policyLannielanning
R
-3

Forget all of the previous answers. If it’s not working, just run the following command if you have installed nvm:

nvm alias 12.16.0 // Add your required Node.js version
Remde answered 12/2, 2020 at 7:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.