How to upgrade node to specific version in macOS Mojave, and update the active path for node?
Asked Answered
F

5

16

I want to upgrade node to 12.10.0 and npm to 6.11.3, currently I am working on macOS Mojave version 10.14.5

I am using these commands to upgrade the node version to 12.10.0::

  1. sudo npm cache clean -f (force) clear you npm cache
  2. sudo npm install -g n install n (this might take a while)
  3. sudo n 12.10.0 upgrade to the specific version

After running the last command it gives me an output like::

installing : node-v12.10.0
       mkdir : /usr/local/n/versions/node/12.10.0
       fetch : https://nodejs.org/dist/v12.10.0/node-v12.10.0-darwin-x64.tar.gz
   installed : v12.10.0 to /usr/local/bin/node
      active : v10.16.3 at /usr/local/opt/node@10/bin/node

When I am checking for node version node -v it still shows me old version 10.16.3

I have tried to add node path, but still, it gives me the same output. I have used command sudo nano /etc/path and then added /usr/local/bin/node path to it.

Please suggest me how can I upgrade node to 12.10.0 and npm to 6.11.3 version?

Flibbertigibbet answered 8/10, 2019 at 5:45 Comment(7)
may be this help : #10076490Nessie
@AnkurDubey I am already done with this still shows me same version. You can check above I am using the same command just clearing cache before this.Flibbertigibbet
@AnkurDubey there might be problem in an active path of the node, suggest to me if you have a solution to change its active path.Flibbertigibbet
You have nvm installed on your machine? I just upgrade my node to v12.11.1 and it's working absolutely fine.Nessie
@AnkurDubey No, I have not installed nvm yet.Flibbertigibbet
Try nvm it will make things easy for you also with nvm you can use multiple node versions currently i have node 8, 10 and 12 installed in my macOS (Mojave) all i have to do is nvm use v8.9.4 if i want to use that version.Nessie
Let us continue this discussion in chat.Nessie
N
26

Install nvm following below tutorial :

Install nvm with homebrew

As stated in the link above,

Start by :

brew update
brew install nvm
mkdir ~/.nvm
nano ~/.bash_profile

In your .bash_profile file (you may be using an other file, according to your shell), add the following :

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

Back to your shell, activate nvm and check it (if you have other shells opened and you want to keep them, do the same) :

source ~/.bash_profile
echo $NVM_DIR

Then with the help nvm install any node version(example v12.14.1) you want :

nvm install v12.14.1
nvm use v12.14.1

to switch to 12.14.1 version.

Nessie answered 8/10, 2019 at 6:46 Comment(0)
D
8

Step 1: Clean npm cache

sudo npm cache clean -f

Step 2: Install node helper (n) globally using the following command.

sudo npm install -g n

Once node helper is installed. You can either get a specific version like I needed 16.14.1 then you can perform.

sudo n 16.14.1

OR You can get the latest stable version using

sudo n stable

Then you can confirm the version installed

node --version 
Deina answered 31/5, 2022 at 20:37 Comment(0)
R
3

install n (npm module) npm install -g n and run sudo n latest or sudo n <version>

Rameses answered 5/8, 2021 at 4:27 Comment(0)
H
1

1-first clean :

sudo npm cache clean -f

2-install npm :

sudo npm install -g n

3- install the lastet version , with out give the virsion number:

sudo n stable

4- check the version with the web site:

node --version
Handling answered 14/11, 2023 at 22:35 Comment(0)
J
0

An alternate way to upgrade w/o using brew -

Go to nodejs releases page. The table on this page list the various node release available for download.

Click on the downloads link for the version you need. This will take us to another page to download the node version depending on the OS you are using. For mac, we can download the .pkg format.

After the package is downloaded, we can run it by clicking the downloaded file and hitting 'Next' till we complete.

Judicative answered 8/3, 2021 at 9:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.