Как изменить версию node js mac os

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

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.

Tot Zam's user avatar

Tot Zam

8,20610 gold badges49 silver badges74 bronze badges

asked Jul 1, 2012 at 18:33

afterglowlee's user avatar

afterglowleeafterglowlee

11.3k5 gold badges20 silver badges23 bronze badges

7

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

answered Oct 12, 2013 at 11:36

Johan Dettmar's user avatar

Johan DettmarJohan Dettmar

27.1k4 gold badges32 silver badges28 bronze badges

18

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 nvm:

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.

answered Jul 2, 2012 at 17:24

wprl's user avatar

22

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

answered Dec 27, 2013 at 6:36

Kennedy Nyaga's user avatar

Kennedy NyagaKennedy Nyaga

3,4131 gold badge25 silver badges25 bronze badges

8

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

answered Sep 7, 2012 at 7:28

Spoeken's user avatar

SpoekenSpoeken

2,4792 gold badges27 silver badges40 bronze badges

10

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.

answered Mar 8, 2013 at 21:55

fijiaaron's user avatar

fijiaaronfijiaaron

4,9333 gold badges35 silver badges28 bronze badges

2

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

npm install -g n

then

n latest

OR

n stable

answered Jul 22, 2016 at 12:47

Shaikh Shahid's user avatar

1

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

Community's user avatar

answered Oct 11, 2016 at 14:03

Tarandeep Singh's user avatar

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.

answered Nov 25, 2020 at 15:23

Mostafiz Rahman's user avatar

Mostafiz RahmanMostafiz Rahman

7,9777 gold badges55 silver badges72 bronze badges

2

On macOS the homebrew recommended way is to run

brew install node
npm install -g npm@latest

Screenshot of Terminal Commands

answered Jan 6, 2015 at 7:14

Nick Woodhams's user avatar

Nick WoodhamsNick Woodhams

11.6k10 gold badges50 silver badges52 bronze badges

1

I am able to upgrade the node using following command

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

answered May 30, 2017 at 10:03

RohitK's user avatar

RohitKRohitK

1,40414 silver badges36 bronze badges

0

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. You can refer to this sample use case for updating Node.js on old Mac (High Sierra).

answered Feb 1, 2022 at 3:40

mikaelfs's user avatar

mikaelfsmikaelfs

3713 silver badges3 bronze badges

Now this works for me:

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

Happy code!

answered Apr 24, 2022 at 20:01

Mario Inostroza's user avatar

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

answered Jun 1, 2018 at 2:47

Jannomeister's user avatar

2

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

iSkore's user avatar

iSkore

7,2343 gold badges36 silver badges58 bronze badges

answered Apr 19, 2016 at 8:37

Lucas Liu's user avatar

Lucas LiuLucas Liu

7831 gold badge9 silver badges12 bronze badges

Pretty Simple.

  sudo npm i -g n

Then you can specify the version you want.

sudo n 12.8.0 

Cheers!!

answered Jan 25, 2022 at 9:54

Maheshvirus's user avatar

MaheshvirusMaheshvirus

6,0991 gold badge37 silver badges38 bronze badges

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

answered Apr 15, 2014 at 13:39

Igor Escobar's user avatar

Igor EscobarIgor Escobar

1,0271 gold badge11 silver badges13 bronze badges

1

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

answered Apr 4, 2016 at 5:06

BRogers's user avatar

BRogersBRogers

3,5044 gold badges23 silver badges32 bronze badges

1

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.

answered Apr 10, 2017 at 12:18

user4810973's user avatar

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

answered Oct 5, 2018 at 12:43

Saviah Kao's user avatar

Saviah KaoSaviah Kao

3101 gold badge4 silver badges13 bronze badges

1

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/

answered Aug 16, 2019 at 5:37

Narendranath Reddy's user avatar

sudo npm install -g n

and then

sudo n latest for linux/mac users

For Windows please reinstall node.

lmiguelvargasf's user avatar

answered Nov 30, 2017 at 13:15

sumanth reddy's user avatar

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

answered May 23, 2018 at 11:31

Rubin bhandari's user avatar

3

for latest release:
nvm install node

specific version:
nvm install 6.14.4

https://github.com/creationix/nvm

answered Oct 24, 2018 at 23:41

Deke's user avatar

DekeDeke

4,3124 gold badges42 silver badges62 bronze badges

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

answered Feb 5, 2018 at 5:02

radhey shyam's user avatar

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

answered Apr 16, 2019 at 14:58

user846316's user avatar

user846316user846316

5,7775 gold badges27 silver badges39 bronze badges

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

answered Jan 13, 2022 at 6:51

Fotios Tsakiris's user avatar

Fotios TsakirisFotios Tsakiris

1,0421 gold badge14 silver badges22 bronze badges

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)

answered Nov 7, 2018 at 13:44

fypnlp's user avatar

fypnlpfypnlp

1,2043 gold badges16 silver badges36 bronze badges

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.

answered Dec 19, 2019 at 14:54

rogopag's user avatar

rogopagrogopag

1011 silver badge3 bronze badges

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

answered May 31, 2022 at 1:16

K.tin's user avatar

K.tinK.tin

3871 silver badge7 bronze badges

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

answered Sep 1, 2022 at 21:32

Pamela Cook - LightBe Corp's user avatar

Node.js version 18.3.0 is currently the latest, and yours might differ depending on when you read this article. Web Development is changing rapidly. Development is picking rapidly, and Node.js is shipping out the new version to almost everyone; therefore, it is nice to have the latest version in your development environment to test the new features and make it compatible with other Javascript libraries.

Why you should upgrade the node

You have many reasons why you should update the node to the latest version because the Javascript community is getting bigger, and so is the NPM repository.

All the new JS frameworks and libraries require the latest node.js version because they are built on the newest technology, and to keep up with that. You also need to update all of your outdated libraries, especially Node.js.

Let me give you a scenario if you are using the current date’s latest version of React, which is React 16.2.0, and you have a node.js version of, let’s say, 9.0, then you won’t be able to even install the React.js project due to some outdated libraries of node.js.

You need to update the latest version to work with other JS libraries and frameworks.

Even node.js is improving from its previous version, so there are many reasons to upgrade your node.js to the latest version. Getting left behind will be the never option for you.

To update node version on mac:

  1. Using N: An npm-based node version manager.
  2. Using Homebrew: Type this command: brew upgrade node
  3. Using NVM: A script-based node version manager.

Update Node using N

N is an npm-based node version manager. I assume that you already have some version of the node installed on your machine. You can install the first node version and then run the following command.

sudo npm install -g n.

Assuming you have successfully installed n. It is the simplest way.

The following command will install the latest version of the node. Please hit that command in admin mode.

sudo n latest

It will install the latest version of Node.js.

Update Node version on Mac

To update Node version on Mac, use the brew upgrade node command. The Homebrew is one of the popular package managers for MacOS. If you are using Mac, Homebrew is the package manager you can use to install different packages.

Assuming you have previously installed node with. Then, with the following command, you can get up-to-date with formulae and upgrade to the latest Node.js version.

brew update
brew upgrade node

It will install the latest version of Node.js.

Update Node using NVM

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

You can install NVM using HomebHomebrewg the following command.

brew install nvm

Now the following command will install the latest version of the node.

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

The last option installs all the global npm packages to your new version.

This way, the packages like mocha and node-inspector keep working.

Conclusions

Upgrading node to the latest version is kid’s stuff, but if you are running in trouble, you can always switch the way to update it.

If you are running into trouble using Homebrew, update the Homebrew and then install one by one missing dependency. It will work fine only after it has all the required dependencies.

If possible, keep your node.js version updated.

That’s it for this article.

Related posts

What is npm

process.env

How to Setup Node Express and MongoDB in Docker

How to create a node.js server

Один из простейших путей как установить Node.Js это пойти на официальный сайт, скачать установочный файл и установить его. Позже разработчики столкнулись с ситуацией, когда им нужно сменить версию Node.js на другую или обновить текущую версию.
Это все еще возможно — установить другую версию с официального сайта, но как много нод уже установлено в системе?

Может быть это хорошее время для удаления их всех и настроить возможность системе переключаться между нодами за секунды, всегда зная количество установленных версий и иметь возможность удалить любые из них одной простой командой.

Как удалить Node.Js с Mac OS

Обо всем по порядку, мы должны удалить старые версии ноды и все связанное с этим. Вы счастливчик, если вы установили прошлые версии с помощью Homebrew. Метод Homebrew это один из простейших вариантов для установки и удаления ноды на маке.

brew uninstall —force node

Напишите эту команду в терминале. Brew удалит все установленные версии Node.Js

После этого, лучше всего, запустить brew cleanup, это удалит все неиспользуемые зависимости и папки.

brew cleanup

Если ваша Node.js была установлена по другому, это не проблема. Вы можете удалить вручную. Есть куча папок, они могут быть удалены одна за одной через файндер или терминал.

Список папок, где находятся Node.js и npm

  • node и/или node_modules в папке /usr/local/lib
  • node и/или node_modules в папке /usr/local/include
  • node, node-debug, и node-gyp в /usr/local/bin
  • .npmrc в вашей домашней директории (Это настройки npm, не удаляйте этот файл, если хотите далее переустановить Node.js)
  • .npm в вашей домашней директории
  • .node-gyp в вашей домашней директории
  • .node_repl_history в вашей домашней директории
  • node* в /usr/local/share/man/man1/
  • npm* в /usr/local/share/man/man1/
  • node.d в /usr/local/lib/dtrace/
  • node в /opt/local/bin/
  • node в /opt/local/include/
  • node_modules в /opt/local/lib/
  • node в /usr/local/share/doc/
  • node.stp в /usr/local/share/systemtap/tapset/

В случае, если вы не хотите вручную искать и удалять все эти папки и файлы, вы можете ввести одну простую команду в терминал:

sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}

Эта команда не трогает вашу домашнюю директорию, так что в дальнейшем вы можете сами решить, что делать с сохранившимися файлами.

Сейчас мы можем удалить все глобальные пакеты, установленные с npm

rm -rf ~/.npm

После всех этих команд, Node.js и npm будут полностью удалены с вашего компьютера.

Как установить Node.js на Mac OS

После очистки, мы можем продолжить с установкой новой версии Node.js. Но мы сделаем это не прямым путем. Потому что если мы сделаем это по обычному, мы все еще будем иметь ту же проблему с кучей версий в будущем.

У данного скрипта есть единственная зависимость — установленная Command Line Tools. Если у вас все еще это не установлено, вы должны запустит команду в терминале:

xcode-select —install

Итак, мы готовы установить NVM. Простейший путь это сделать — .sh скрипт.

Скачать и установить данный скрипт мы можем с помощью следующей команды:

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

0.37.2 — последняя версия на день написания статьи. Версия может быть проверена на странице NVM в GitHub

Конечно, это может быть установлено вручную. Вы нужно склонировать репозиторий и добавить необходимы файлы в PATH. Детальная инструкция описана в NVM ReadMe. Это будет полезно если вам нужно использовать NVM в CI пайплайн. Я бы рекомендовал добавить NVM в Docker image, который использует ваш пайплайн.

Не забудьте перезапустить окно терминала для обновления переменных окружения

Мы почти закончили. Сейчас мы легко можем установить любую версию Node.js. Для примера, эта команда установит самую свежую версию:

nvm install node

Если вы хотите установит LTS версию, но с последней версией npm, сделайте следующее:

nvm install —lts —latest-npm

Используя флаги, вроде —lts вы можете использовать любую версию.

nvm install 8.9.1 # or 10.10.0, 12, etc

Для того, что бы увидеть список установленных версий, вам нужно запустить команду:

nvm list

После установки, вам нужно выбрать дефолтную версию для вашей системы:

nvm use —lts

Что о пользователях Windows?

Для windows доступен похожий скрипт: Node Version Manager (nvm) for Windows. Это другой проект, который делает то же самое. Вы так-же можете устанавливать/удалять/выводить список и переключать любые версии Node.js

Итоги

С NVM вы получаете:

  • Простую установку/удаление любой версии Node.js
  • Лучший скрипт для переключения между нодами.
  • Удаление такое же простое, как и установка

Вы почувствуете это в будущем, особенно, когда в следующий раз будете обновлять свою Node.js.

Спасибо за прочтение!

Переведено: Голдобин Антон

Node.js is one of the most popular development platforms nowadays. It allows developers to create server-side applications using JavaScript. Updating Node versions can be tricky, but it’s crucial for your development environment.

Sr Engineer teaching how to update node versions

Download Now: An Introduction to Java & JavaScript

This blog post will take you through updating Node.js on Mac, Windows, and Linux. We’ll also give you some tips to make the process as smooth as possible. First, we’ll discuss why keeping your Node up-to-date is essential.

Let’s get started!

Why is it important to keep Node up-to-date?

Node.js is an open-source platform. New features, bug fixes, and security updates are constantly released. Newer versions of Node.js will have better performance, stability, and security. That’s why it’s essential to keep up-to-date with the latest version of Node

Why update the Node version, if a project already runs smoothly?

Keeping your Node up-to-date ensures your code runs with the latest security and bug fixes and gets access to the latest features. If you don’t keep your Node up-to-date, it could lead to security vulnerabilities and other issues. Even if your code is impeccable, any third-party code integrated into your work — directly or indirectly — can have its own security faults.

Now that we know how important it is to update Node, how do you update it? Let’s look at updating Node on Mac, Windows, and Linux.

There are a few ways to update Node on Mac and Windows. We’ll talk about using a package manager such as NPM or manually downloading the latest version and installing it yourself.  

Using NPM:

To update Node using NPM, do the following:

  1. Open the Terminal and check your current Node version: 
    node -v 
  2. Install n package using the following command:
    npm install -g n   
    This command will install a tool called «n» which you can use to update Node easily.
  3. To update Node, run the following command in your terminal:           
    n latest
    This command will install the latest version of Node on your system.
  4. Now you can verify that your update is complete by rechecking your Node version:  
    node -v

You can also manually download and install the latest Node version from the official website.

How to Update Node Versions on Linux

Updating Node on Linux is a bit different from how it’s done on Windows and Mac. To update Node, you’ll need to use a package manager such as NVM or APT.

Using nvm:  

NVM (Node Version Manager) is a tool that allows you to manage multiple versions of Node on your system. You can use nvm to install, update, and switch between different versions of Node.

To update your version of Node using nvm, do the following:

  1. Check if you already have nvm installed on your system:  
    nvm —version
  2. If it’s not installed, install nvm using this command:    
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
  3. Once nvm is installed, check your current version of Node by running the following command:
    node -v
  4. Then update your version of Node using the following command:  
    nvm install node —reinstall-packages-from=node
  5. And finally, verify that your update is complete by rechecking your Node version:  
    node -v

Using APT (Advanced Package Tool):

APT is a package manager for Debian-based Linux distributions such as Ubuntu and Debian. To update Node using APT, do the following:

  1. First, check your current version of Node by running the following command:
    node -v
  2. Then run this command to install the latest version of Node:    
    sudo apt-get install nodejs
  3.  And finally verify that your update is complete by rechecking your Node version:  
    node -v

These are just a few ways to update Node on Mac, Windows, and Linux. Keep in mind that it’s important to keep up-to-date with the latest version of Node not only for security reasons but also to get access to new features and bug fixes.

Tips For Updating Your Node Version

Updating Node versions can be a simple process. Here are some tips to make it easier:

  • Make sure your existing Node version is up to date before upgrading. You may experience issues during the updating process if it still needs to be updated.
  • Test any new features or bug fixes on a development environment before deploying them to production. This will help ensure that everything works as expected before making any changes live.
  • Ensure your development environment is backed up regularly if anything goes wrong during the upgrade process.
  • Keep an eye on the Node release notes for new updates or software changes.

By following these tips and using the above methods, you can ensure that your node version is always up-to-date with the latest features and security patches!     

Final Thoughts on Updating Node Version

The benefits of Node.js is countless. From its easy-to-use environment, modern features, and constant updates, Node is a popular choice for developing applications. Keeping your version of Node up-to-date is important to get the best performance, security, and features out of it. With multiple options available such as Mac, Windows, and Linux,  updating Node is accessible and can be done quickly with just a few steps.

java

Introduction

Node.js is an open-source JavaScript runtime environment. Since Node.js has an active community of users, minor updates of the software come out every few weeks.

You may be using Node.js as a layer of the MEAN stack or in a different JS framework. Either way, make sure to update Node.js regularly to ensure system security.

There are several ways to install Node.js and NPM. Likewise, there are several ways to update your Node.js version, depending on the operating system running on your machine.

In this article, you will learn how to update to the latest Node.js version on Linux, Windows, and macOS.

tutorial on how to update Node.js to latest version

3 Ways to Update Node.js to Latest Version on Linux Systems

There are different ways to update Node.js if you are using a Linux-based system. Although using the Node Version Manager is the easiest and most recommended option, you can also update with the local package manager or by downloading the binary packages.

Option 1: Update Node.js with NVM (Node Version Manager)

The best way to upgrade Node.js is with NVM, a practical tool for managing multiple Node.js 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

Note: If you don’t have curl, install the utility by running the command: sudo apt install curl.

Alternatively, you use wget and run the command:

wget -q0- 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

5. Then, verify if you have successfully installed NVM:

nvm --version

6. Before upgrading Node.js, check which version you have running on the system:

nvm ls

7. Now you can check for newly available releases with:

nvm ls-remote
see a list of all available Node.js versions

8. To install the latest version, use the nvm command with the specific Node.js version:

nvm install [version.number]

Option 2: Update Node.js with NPM (Node Package Manager)

As an alternative, you can use Node’s official package manager to update Node.js. NPM is a tool for installing and managing package dependencies.

If you have Node on your system, you have NPM, as well. With the npm command, you can check running Node.js versions and install the latest release.

By adding the n module, you can interactively manage Node.js versions.

1. First, clear the npm cache:

npm cache clean -f
clear npm cache

2. Install n, Node’s version manager:

npm install -g n

3. With the n module installed, you can use it to:

Install the latest stable version:

sudo n stable

Note: Some Ubuntu distros may respond with the command not found output after running the n command. To fix this issue run sudo -E env "PATH=$PATH" [command]. For example, to install the latest stable version, as in the example above, you would run sudo -E env "PATH=$PATH" n stable.

Install the latest release:

sudo n latest

Install a specific version:

sudo n [version.number]

Option 3: Update Node.js with Binary Packages

Updating Node.js with binary packages is the least recommended option. However, if it is the only way you can upgrade to the latest Node.js version, follow the steps outlined below.

1. Navigate to Node’s official downloads page where you can find all available packages. There you can download the source code or pre-built installer for the LTS versions or the latest release.

2. You can either download the package from your browser or find the version number you need and add it to the wget command:

wget https://nodejs.org/dist/v14.17.0/node-v14.17.0-linux-x64.tar.xz

3. Next, install xz-utils used to extract the binary package:

sudo apt-get install xz-utils

4. Extract and install the package with the command:

sudo tar -C /usr/local --strip-components 1 -xJf node-v14.17.0-linux-x64.tar.xz

Updating Node.js on Windows and macOS follows the same principles.

There are two simple ways to upgrade:

  • Download the latest Node.js release from its official download page and install the new Node.js release.
  • Install the n module and update Node.js inside the terminal window.

Option 1: Update Node.js on Windows and macOS with Installer

One way to update your Node.js is to go to its official download page and install the newest release. Bz doing so, the system should overwrite the older version with the updated one.

1. Navigate to the Node.js website and click on the latest stable version or the newest current release (with the latest features).

2. After deciding the version, click on the Windows or the macOS Installer, depending on the system you are using. The system downloads the package and stores it in the specified directory.

3. Once the download is complete, run the installer.

4. The Node.js Setup Wizard appears and guides you through the installation.

Node.js installation wizard

5. Accept the License Agreement by checking the box and click Next.

Node.js licensing agreement

6. Choose the destination folder where you want to install Node.js.

install latest Node.js on Windows

7. Node.js allows you to select how you want to install the Node features. Change the way the features are installed by clicking on the icons in the tree.

Custom Setup for Node.js

8. With that, the latest Node.js is ready to install. Click Install to confirm, wait until the installation completes, and click Finish.

9. Check the Node.js version with the command:

node -v

Note: Sometimes, the system fails to overwrite the older Node.js release and you may end up with two versions. If such problems occur, you may want to consider updating with NPM, outlined in the section below.

Option 2: Update Node.js on Windows and macOS with NPM

If you want to upgrade Node.js from the command line, use the n model within the npm command. The n feature allows you to interact with different Node.js versions.

1. Before updating the Node.js release, check which version you are currently using with:

node -v

2. Next, clear npm cache with the command:

npm cache clean -f

3. Install n globally:

npm install -g n

4. Now that you have n installed, you can use the module to install the latest stable release of Node.js:

sudo n stable

Alternatively, you can install the Node.js release with the latest features:

sudo n latest

Or, install a specific version number with:

n [version.number]

Conclusion

The best part of open-source technology is its strong community of users constantly working on upgrading the software.

Node.js is a good example of such software as new versions come out regularly. Users can choose whether they want to work with the LTS (the long-term supported version) or the latest version with the newest features.

This article should have helped you update Node.js on any operating system.

Понравилась статья? Поделить с друзьями:
  • Как изменить версию mysql server
  • Как изменить версию mysql ispmanager
  • Как изменить версию miui на xiaomi
  • Как изменить версию minecraft windows 10 edition
  • Как изменить версию minecraft java edition