Upgrade Node.js to the latest version on Mac OS
Asked Answered
C

32

1031

Currently I am using Node.js v0.6.16 on Mac OS X 10.7.4. Now I want to upgrade it to the latest Node.js v0.8.1. But after downloading and installing the latest package file from nodejs.org, I found that system is still using v0.6.16 instead of v0.8.1 when I typed "node -v" in a terminal. Is there any step that I have missed? Or, should I thoroughly uninstall the old version before installing the latest one?

BTW, I know that nvm can help to manage the nodejs package

https://github.com/creationix/nvm/

Is there any way to upgrade the Node.js without using it?

I have googled this problem, but it seems to me that there is no very clear answer to this question for the latest Node.js.

Capitate answered 1/7, 2012 at 18:33 Comment(8)
Not sure on an answer, but for clarification is a Node process running when you update it?Monjo
No, I don't think there is any Node process running. And after restarting the OS, the "node -v" command still shows v0.6.16 is running.Capitate
You might want to first double check you have it installed with brew apple.stackexchange.com/questions/101090/…Litchfield
Folks - this is a 6 year old question and with some equally old answers. No doubt that they were the best practices back then. But as of 2018, brew upgrade node should work just fine. Please see the answer by wprl below.Cheliform
@Cheliform As of February 2019, the npm website actually recommends using a Node version manager like n or nvm to install and upgrade both Node and npm.Ravelin
You can just download the latest installer from the official website. nodejs.org/en/downloadSavagism
I got this issue, because of unnecessary import 'node-sass', which was not required, by remove that import source worked very well. this one is 2021 issue with similar error message inside react.Winstonwinstonn
Just use "nvm install <version>"Spelldown
F
1957

Here's how I successfully upgraded from v0.8.18 to v0.10.20 without any other requirements like brew etc, (type these commands in the terminal):

  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 stable upgrade to the current stable version

Note that sudo might prompt your password.

Additional note regarding step 3: stable can be exchanged for latest, lts (long term support) or any specific version number such as 0.10.20.

If the version number doesn't show up when typing node -v, you might have to reboot.

These instructions are found here as well: davidwalsh.name/upgrade-nodejs
More info about the n package found here: npmjs.com/package/n
More info about Node.js' release schedule: github.com/nodejs/Release

Fatimahfatimid answered 12/10, 2013 at 11:36 Comment(14)
worked to update node from v0.10 to v0.12 in macos x snow leopard. Thank you.Pageantry
FWIW you can use 'n lts' to install the long term support version rather than the current stable version (i.e. 4.4.3 instead of 5.10.1 at the time of writing)Express
Note step 1 force clears your cache. You'll get the warning: npm WARN using --force I sure hope you know what you are doing.Cabral
Brew is occurring error. This is the correct answer, currently.Chak
you can do sudo n latest as the final step alsoPrincedom
sudo n lts as the last step gets you a Long Term Support versionGunpowder
Perfect @osx node upgraded to 9.8.0Gaivn
Thanks, It helped as brew with sudo is no longer supported.Plow
I didn't need to clear my cache, but maybe I made a mistake in not doing soProwler
I tried a couple of from this answer thread But Only This Solutions works for me. @Johan Dettmar, Thanks for the answer. I upgraded from 8.x to 10.10.0Airglow
This worked, but no one explains what the commands why installing "n" helps. I just figured out today that "n" is a Node.js version manager, as somewhat explained on the npm js website - npmjs.com/get-npmBust
Doing this is enough npm cache clean -f & npm install -g nodeLimb
Working on Mojave 10.14.12 to upgrade Node form 8 to v14.17.5 and npm to 6.14.14.Akkerman
This does not set the active node version for homebrew. How do I set the active node version?Waddle
F
1036

If you initially installed Node.js with Homebrew, run:

brew update
brew upgrade node
npm install -g npm

Or as a one-liner:

brew update && brew upgrade node && npm install -g npm

A convenient way to change versions is to use n:

brew install n

To install the latest version of Node.js with n:

n latest

Or, to install the latest LTS version with n:

n lts

Alternatively, you could use nvm instead of n:

brew install nvm

To install the latest version of Node.js with nvm:

nvm install node

If you installed via a package, then download the latest version from nodejs.org. See Installing Node.js and updating npm.

Fixity answered 2/7, 2012 at 17:24 Comment(23)
Hi SoloBold, thanks for your reply. I didn't use brew. I install the orignal v0.6.16 from the pkg file provided by nodejs.org. So I can't use "brew update node".Capitate
@Capitate You might try uninstalling the old node before reinstalling the new one: #9045288Fixity
Yeah. It seems to be the only way currently to do it. I will try and see if it works.Capitate
Thoroughly removing and reinstalling NodeJS works. But I really suspect if it is the proper way to upgrade NodeJS on Mac OS. So as a summary, on Mac OS, we'd better use some tools, such as nvm and brew, to manage the version of NodeJS.Capitate
Interestingly, the brew formula for node seems to just do a ./configure && make install; I'm not sure what exactly brew does in the upgrade process, but it should be reproducible by hand if necessary. A place to start, anyway :) github.com/mxcl/homebrew/blob/…Fixity
Yeah, it also seems weird to me. Maybe I am quite a newbie to NodeJS. Now I am using nvm to manage my NodeJS version. Nvm downloaded the sourcecode of v0.8.1 and make a couple of links: ln -fs out/Release/node node out/Release/node tools/installer.js install cp -rf src/node.h /Users/user/projects/nvm/v0.8.1/include/node/ ln -sf ../lib/node_modules/npm/bin/npm-cli.js /Users/user/projects/nvm/v0.8.1/bin/npm shebang #!/Users/user/projects/nvm/v0.8.1/bin/node Now using node v0.8.1 There must be some way to configure it in Mac OSCapitate
I just upvoted this answer, but after 7 mins wait, brew told me installation failed... I also tried port upgrade node, but brew already messed up the package and port can't find node now... Finally I went to nodejs.org to download the installation package, and boom! Everything goes well, including the npm!Kronstadt
@Jinzhao It's recommended not to install more than one of Homebrew, MacPorts, or Fink.Fixity
I am using Homebrew and everything works except being able to update npm. I get npm WARN package.json [email protected] No repository field. /usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js [email protected] /usr/local/lib/node_modules/npmBiddable
@user2197606 have you run brew doctor and brew update recently?Fixity
in current brew version it states "If you update npm itself, do NOT use the npm update command. The upstream-recommended way to update npm is: npm install -g npm@latest"Sochor
@Sochor they've since fixed the npm update -g npm command. github.com/Homebrew/homebrew/commit/…Hubbard
I hate update packages with brew by symlinks problems, for this time i used the node dpkginstaller.Marginate
I used homebrew to remove node, then followed the instructions given. The only thing I needed to do was npm install -g n for and then use n stable to use the most current node versionAkanke
Run npm install -g node after following above instructions if your node version is still not updated.Catboat
You can also simply run: npm i -g npm.Christy
I strongly advise against installing nvm via brew, you can see that mentioned in the readme on github.com/creationix/nvm Personally I have a hard time remove outdated nvm installed via brew. Also when you have node, npm, nvm with non compatible across all major version this create a triangle of dependencies. It's really hard to reason what's going on when things do not work. I would just neutralize nvm before upgrading node/npm.Michaeline
i wish there was some way to determine whether I installed a piece of software using brew, port, or some other mechanism, because I can never remember!Bowe
Much, much easier to use the n package (as other answers say) than having to deal with brew's shenanigans.Heriot
I am on Mac :> brew upgrade node Warning: node 17.5.0 already installed but npm -v 6.14.15Rale
brew update && brew upgrade node && npm install -g npm not work with error info: Error: node not installedLithomarge
Sorry for confusing here, my condition is complex. I installed brew and node in an intel chip and then restore it back arm chip. However, brew in arm use /opt/homebrew/Cellar not /usr/local/CellarLithomarge
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!Annapolis
I
225

Because this seems to be at the top of Google when searching for how to upgrade nodejs on mac I will offer my tip for anyone coming along in the future despite its age.

Upgrading via NPM
You can use the method described by @Mathias above or choose the following simpler method via the terminal.

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

After which you may opt to confirm the upgrade

node -v

Your nodejs should have upgraded to the latest version. If you wish to upgrade to a specific one say v0.8.19 then instead of

sudo n stable

use

sudo n 0.8.19

EDIT Avoid using sudo unless you need to. Refer to comment by Steve in the comments

Imponderable answered 27/12, 2013 at 6:36 Comment(8)
Why would you downvote an answer and not add a comment explaining why?Imponderable
Because you advice to use sudo.Semifinal
This works, but: is it really necessary to use the --force flag on cache clean? And I didn't need sudo for the first two commands.Compressed
Thanks @SteveBennett for adding that, I added sudo in order to include newbies who would need it, rather than leave them stranded. Moreover, having sudo will work in both cases.Imponderable
Sometimes using sudo when it's not needed actually makes a mess, because you end up with files owned by root, which then can't be modified without sudo.Compressed
nice answer. Worked fine.Platitudinize
Can I do sudo n latestCircumambient
I had then a couple of versions and was using the old (active). To change the version that is active [ n use 0.0.0] worked to swap versions.Unni
L
78

Go to http://nodejs.org and download and run the installer. It works now - for me at least.

Lamaism answered 7/9, 2012 at 7:28 Comment(10)
Do you know by any chance how installed jode.js updates in OS/X?Vandyke
Im not sure I understand what you are askingLamaism
Sorry for the confusion (wrote in a hurry). I have installed node.js straight from the site's download link, Current Version: v0.8.14. When say v0.8.15 gets released, will I have to download it again, will it auto-update, will it call-home and inform me? With homebrew for example I was doing a brew upgrade (so it was up to me)Vandyke
I don't think it will call home. You will have to check regularly and download the new version from their webpage i think. But im not 100% on this.Lamaism
probably the easiest way here.Diuresis
Likely the only thing that works in all cases. Just do it this way. But I somehow had another node installed in /opt/local/bin I had to remove cause it was taking precedence in my PATH.Junco
Instead of messing around with brew and its errors, this way works!Limn
This works well with intel Mac . Anyone tried this with M1 Mac?Devalue
@XSham shouldn't be any different? I would get nvm tho, it makes it super easy to switch version.Lamaism
It works in macPilgrimage
P
58

You could install nvm and have multiple versions of Node.js installed.

curl https://raw.github.com/creationix/nvm/master/install.sh | sh
source ~/.nvm/nvm.sh

and then run:

nvm install 0.8.22  #(or whatever version of Node.js you want)

you can see what versions you have installed with :

nvm list

and you can change between versions with:

nvm use 0.8.22

The great thing about using NVM is that you can test different versions alongside one another. If different apps require different versions of Node.js, you can run them both.

Pastelist answered 8/3, 2013 at 21:55 Comment(2)
I am using this method now. It seems to me that this is the best way to keep multiple versions running at the same machine.Capitate
If you set zch to be your default shell, that will not work. Installing nvm will error on trying to update the .bash_profile file. You will need to install github.com/lukechilds/zsh-nvm or edit the zch bash profile manually.Allynallys
D
39

I use Node version manager (called n) for it.

npm install -g n

then

n latest

OR

n stable
Demilitarize answered 22/7, 2016 at 12:47 Comment(1)
LTS version n ltsCelina
M
30

Simply go to node JS Website and install the latest version.

Do install latest version instead of the recommended stable version. It will give you freedom to use latest ES6 Features on node.

Can be Found here Node JS.

also to update npm, you will have to use this command.

sudo npm i -g npm@latest

All your projects will work fine.

Update: 2020 another good option is to use nvm for node which can then support multiple versions. use nvm install --lts to always be able to update to latest node version use nvm ls-remote command to to check new versions of node.


Other option for mac :: brew update && brew install node && npm -g npm

Monstrosity answered 11/10, 2016 at 14:3 Comment(0)
H
27

Upgrade the version of node without installing any package, not even nvm itself:

sudo npx n stable

Explanations:
This approach is similar to Johan Dettmar's answer. The only difference is here the package n is not installed glabally in the local machine.

Hike answered 25/11, 2020 at 15:23 Comment(2)
fast, clean and beautiful!Kef
Clean and Beautiful. should be as acceptable answer.Unfrock
D
25

On macOS the homebrew recommended way is to run

brew install node
npm install -g npm@latest

Screenshot of Terminal Commands

Dismay answered 6/1, 2015 at 7:14 Comment(1)
It will install the truly latest version, not just the most current brewed version.Dismay
M
15

There are five different ways (and counting?) to update Node.js on Mac:

  1. Install the newer binary by downloading from nodejs.org

  2. Update Node.js through Homebrew

    Command: brew update && brew upgrade node

  3. Update Node.js using Node Version Manager (NVM)

    Command: nvm install {version} && nvm use {version}

  4. Update Node.js using n package manager

    Command: sudo n latest

  5. Update Node.js through MacPorts

    Command (same version update): sudo port selfupdate && sudo port upgrade {version}

If you are still using older MacOS version, it may be better to use lightweight, special-purpose package manager like n or nvm.

Mercado answered 1/2, 2022 at 3:40 Comment(1)
What if I just want to upgrade to the LST version? the brew update && brew upgrade node seems to work for the Current versionColdshoulder
P
12

I am able to upgrade the node using following command

nvm install node --reinstall-packages-from=node
Priapism answered 30/5, 2017 at 10:3 Comment(0)
S
10

Now this works for me:

  1. sudo npm install -g n
  2. sudo n latest

Happy code!

Suburbia answered 24/4, 2022 at 20:1 Comment(0)
H
9

Pretty Simple.

  sudo npm i -g n

Then you can specify the version you want.

sudo n 12.8.0 

Cheers!!

Humpback answered 25/1, 2022 at 9:54 Comment(0)
P
7

sadly, n doesn't worked for me. I use node version manager or nvm and it works like a charm. heres the link on how to install nvm: https://github.com/creationix/nvm#installation

  • nvm i 8.11.2 upgrade to latest LTS
  • nvm use 8.11.2 use it
  • node -v check your latest version
Pozzuoli answered 1/6, 2018 at 2:47 Comment(2)
This is the one that worked for me. I tried several of the top comments, but after following the steps, node is still stuck at v6. Thanks!Vivianne
This worked for me. thanks jannomeister. upvote for accepted answer pleaseCulhert
M
6

Easy nad Safe Steps

Step 1: Install NVM

brew install nvm

Step 2: Create a directory for NVM

mkdir ~/.nvm/

Step 3: Configure your environmental variables

nano ~/.bash_profile

PASTE BELOW CODE

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

source ~/.bash_profile

Step 4: Double check your work

nvm ls

Step 5: Install Node

nvm install 9.x.x

Step6: Upgrade

nvm ls-remote

   v10.16.2   (LTS: Dubnium)
   v10.16.3   (Latest LTS: Dubnium) ..........

nvm install v10.16.3

Troubleshooting

Error Example #1
rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh

https://www.chrisjmendez.com/2018/02/07/install/

Macaw answered 16/8, 2019 at 5:37 Comment(2)
Simple & straight forward (Y)Impeccant
those who are on zshrc should update ~./zprofile instead of ~/.bash_profileImpeccant
O
5

Go to the website nodejs.org and download the latest pkg then install. it works for me

I used brew to upgrade my node. It has installed but it located in /usr/local/Cellar/node/5.5.0 and there is a default node in /usr/local/bin/node which bothers me. I don't want to make soft link because I don't really know how brew is organized. So I download the pkg file, installed and I got this info:

Node.js was installed at

/usr/local/bin/node

npm was installed at

/usr/local/bin/npm

Make sure that /usr/local/bin is in your $PATH.

Now the upgrade is completed

Odontograph answered 19/4, 2016 at 8:37 Comment(0)
S
5

These 2 methods I tried are not working:

  1. Use npm

sudo npm cache clean -f

sudo npm install -g n

sudo n stable

  1. Manual install node from official website (https://nodejs.org/en/)

After trying, node -v still shows the old version of node.


Below method works for me:

Step 1: Install nvm (for more details: https://github.com/creationix/nvm#installation)

Open terminal and type this command:

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

Close terminal and reopen it.

Type this command to check if nvm is installed:

command -v nvm

enter image description here

Step 2: To download, compile, and install the latest release of node, type this:

nvm install node ("node" is an alias for the latest version)

To check if node gets the latest version (v10.11.0).

enter image description here

Installing the latest node also installs the latest npm.

Check if npm gets the latest version (6.4.1).

enter image description here

Stenson answered 5/10, 2018 at 12:43 Comment(2)
I found this method is not working for me now. Here is how I did instead: npm install -g n sudo n 10.11.0 (in my case, I just wanna update to 10.11.0) Then it updated to 10.11.0 node -vStenson
After trying alot, nvm install node, worked for me.Bile
F
4

You can run but you can't hide... At the end you will be using NVM anyways.

Fridafriday answered 15/4, 2014 at 13:39 Comment(1)
Or the 'n' package... See Kenny West's answer if you'd like a simple package manager you can install via npm.Lal
A
4

You can just go to nodejs.org and download the newest package. It will update appropriately for you. NPM will be updated as well.

Asceticism answered 4/4, 2016 at 5:6 Comment(1)
By far the easiest, if you initially installed it via de the website.Hurst
D
4

I think the simplest way to use the newest version of Node.js is to get the newest Node.js pkg file in the website https://nodejs.org/en/download/current/ if you want to use different version of Node.js you can use nvm or n to manage it.

Dab answered 10/4, 2017 at 12:18 Comment(0)
C
4
sudo npm install -g n

and then

sudo n latest for linux/mac users

For Windows please reinstall node.

Consecrate answered 30/11, 2017 at 13:15 Comment(0)
G
4

for latest release: nvm install node

specific version: nvm install 6.14.4

https://github.com/creationix/nvm

Granlund answered 24/10, 2018 at 23:41 Comment(0)
C
3

Nvm Nvm is a script-based node version manager. You can install it easily with a curl and bash one-liner as described in the documentation. It's also available on Homebrew.

Assuming you have successfully installed nvm. The following will install the latest version of node.

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

The last option installs all global npm packages over to your new version. This way packages like mocha and node-inspector keep working.

N N is an npm-based node version manager. You can install it by installing first some version of node and then running npm install -g n.

Assuming you have successfully installed n. The following will install the latest version of node.

sudo n latest

Homebrew Homebrew is one of the two popular package managers for Mac. Assuming you have previously installed node with brew install node. You can get up-to-date with formulae and upgrade to the latest Node.js version with the following.

1 brew update
2 brew upgrade node

MacPorts MacPorts is the another package manager for Mac. The following will update the local ports tree to get access to updated versions. Then it will install the latest version of Node.js. This works even if you have previous version of the package installed.

1 sudo port selfupdate
2 sudo port install nodejs-devel
Creosol answered 23/5, 2018 at 11:31 Comment(3)
brew upgrade node is a breezeBernhardt
This is what worked for me on OSX. I probably had NVM installed because node -v kept giving me 6.11.1 even after commands related to n latest and so on. The brew upgrade one worked. Thanks.Toname
Macports isn't finding the "nodejs-devel" package for me. I had to uninstall the old version and install the new one.Speckle
A
1

Use nvm to upgrade node as per the project requirement..

install nvm through homebrew.. 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

source ~/.bash_profile echo $NVM_DIR

Angelicangelica answered 5/2, 2018 at 5:2 Comment(0)
A
1

You can directly use curl to upgrade node to the latest version. Run the following command:

curl "https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\.pkg</a>.*|\1|p')}.pkg" > "$HOME/Downloads/node-latest.pkg" && sudo installer -store -pkg "$HOME/Downloads/node-latest.pkg" -target "/"

Reference: https://nodejs.org/en/download/package-manager/#macos

Ander answered 16/4, 2019 at 14:58 Comment(0)
K
1

First install nvm with this command:

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

credirts to @Saviah Kao

Then install node:

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

credits to @Elad

Kraft answered 13/1, 2022 at 6:51 Comment(0)
M
1

An easy way is go straight to the website https://nodejs.org/en/download/ Click download the latest version and install pkg file. After that you will get the latest node and npm version

Menses answered 31/5, 2022 at 1:16 Comment(0)
S
0

I had the same problem. This is what worked for me because I downloaded and installed node.js globally from the node.js website.

What I did was Give NVM (Node Version Manager) a try. Please do the commands in the following order in your terminal

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

  2. command -v nvm

  3. nvm install node

  4. node -v (to confirm the update)

Seaddon answered 7/11, 2018 at 13:44 Comment(0)
D
0

This is just to add some info for people who didn't have Node installed with Homebrew but getting that very error when trying to install packages with npm on Mac OS X.

I found this good article explaining how to completely remove Node whichever the way you originally installed it.

After node, npm and n were completely removed from my machine, I just reinstalled Node.js using the official .pckg installer from Node website and everything just went back to normal.

Hope this helps out someone.

Drouin answered 19/12, 2019 at 14:54 Comment(0)
H
0

I'm using a Mac Mini M1. I just removed my very old packages of node.js and npm and decided to install them using homebrew. I found out that now brew install node also installs npm. FYI

Highway answered 1/9, 2022 at 21:32 Comment(0)
W
0

i tired lot but not help anything. after search lot of blogs i got this one for mac m1 pro.

nvm install node

this command working fine for me.

enter image description here

Wireworm answered 31/8, 2023 at 14:6 Comment(0)
F
-1

I was able to update in ~20 seconds with just one line of code

sudo n latest

Other commands weren't working for me, but this one worked. Hope it helps somebody.

Fruity answered 15/6, 2018 at 5:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.