How to update nodejs on linux

Upgrading Node.js to latest version

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.

I reinstall nodeJS on windows a few times but it didn’t help, I think it has something to do with visual studio 2015

37 Answers 37

Ubuntu Linux/Mac:

The module n makes version-management easy:

For the latest stable version:

Windows:

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

OSX Yosemite, npm install n -g && n stable worked for me. No need for sudo if node was not previously installed with it.

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 below

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.

All Platforms (Mac, Linux & Windows) 2023

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:

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 

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:

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:

Читайте также:  Mount unknown filesystem type linux raid member

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.

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!

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. @nelsonic your answer is awesome

I took one look at step one and already I didn’t like this solution. The curl command includes a version number on nvm. I’d rather have a command that installs the latest version. Does nvm take care of that on its own? I also don’t like step 2. I’d prefer a command that installs the latest version, and doesn’t require me to know a version number.

@redOctober13 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.

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

and also you can specify a desired version:

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)

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 

You can always check the version with following command:

C:\node -v v0.12.4 C:\npm -version 2.10.1 

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?

All platforms (Windows, Mac & Linux)

Updated May 2021

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.

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

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/

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 detected

Читайте также:  Linux create user with root rights

just downloaded newest version, install, went to command prompt typed node -v , saw change instantly.

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/….

Following Upgrading Node.js to latest version

sudo npm cache clean -f sudo npm install -g n sudo n stable sudo ln -sf /usr/local/n/versions/node//bin/node /usr/bin/node 

For Upgrading Node.js to latest version

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

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

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

Addition n13: in case ‘sudo n stable’ has errors, try this:

sudo -E env "PATH=$PATH" n stable 

Источник

updating nodejs on ubuntu 16.04

I was recently going through the version of node in my ubuntu 16.04 when node -v command was used it shows me version 6.9.1 but when nodejs -v it shows 6.9.2 previously before using this commands npm update command was used. Now what’s these difference in node -v and nodejs -v ? and how to update to the latest LTS version of node/nodejs?

17 Answers 17

To update, you can install n

You can also use sudo n current or sudo n lts if you want more guarantee of stability and don’t need the latest bleeding-edge features.

@thund I upvoted your comment, but actually sudo n current does not exist, I think you mean sudo n stable

node v12 (Old)

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt-get install -y nodejs 

node v14 (For new users: install this one):

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo apt-get install -y nodejs 

node v15 (Current version):

curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash - sudo apt-get install -y nodejs 

Other older versions: Just replace the desired version number in the link above.

Читайте также:  Исходные коды утилит linux

Optional: install build tools

To compile and install native packages

sudo apt-get install -y build-essential 

To update node to the latest version just:

sudo apt update sudo apt upgrade 

To keep npm updated

To find out other versions try npm info npm and in versions find your desired version and replace [version-tag] with that version tag in npm i -g npm@[version-tag]

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

Test your installation:

close your current terminal, open a new terminal, and run:

Use it to install as many versions as u like:

nvm install 8 # Install nodejs 8 nvm install --lts # Install latest LTS (Long Term Support) version 

List installed versions:

Use a specific version:

nvm use 8 # Use this version on this shell 

Set defaults:

nvm alias default 8 # Default to nodejs 8 on this shell nvm alias default node # always use latest available as default nodejs for all shells 

I spent few hours trying to install Node 16 on my Ubuntu 14.04.6 using curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash — . This Solution works fine for me. Thanks

Use n module from npm in order to upgrade node

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

To upgrade to latest version (and not current stable) version, you can use

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

Use sudo apt-get install —only-upgrade nodejs to upgrade node (and only upgrade node) using the package manager.

The package name is nodejs , see https://stackoverflow.com/a/18130296/4578017 for details.

You can also use nvm to install and update node.

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

Then restart the terminal, use nvm ls-remote to get latest version list of node, and use nvm install lts/* to install latest LTS version.

nvm is more recommended way to install or update node, even if you are not going to switch versions.

Difference: When I first installed node, it installed as ‘nodejs’. When I upgraded it, it created ‘node’. By executing node, we are actually executing nodejs. Node is just a reference to nodejs. From my experience, when I upgraded, it affected both the versions (as it is supposed to). When I do nodejs -v or node -v, I get the new version.

Upgrading: npm update is used to update the packages in the current directory. Check https://docs.npmjs.com/cli/update

To upgrade node version, based on the OS you are using, follow the commands here https://nodejs.org/en/download/package-manager/

Please refer nodejs official site for installation instructions at the following link

Anyway, please find the commands to install nodejs version 10 in ubuntu below.

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y nodejs 

Источник

Оцените статью
Adblock
detector