Как обновить node js через консоль windows

Today’s article falls into the category “reminder”. Every few months I write smaller projects with Node.js. But before I start, I’d like to update to the latest version, and that’s where the dilemma starts. Every time I forget the command line commands for it.

Therefore, here are the short and concise CMD/Shell/Bash commands for updating Node.js and NPM. Once for macOS (OSX) / Linux and once for Windows.

Update NPM on Linux and macOS (OS X)

sudo npm install -g npm

Whether the update was successful can be tested with the following command.

npm -v

Update NPM on Windows

The following commands have to be set in Powershell (Start -> “powershell” -> right click -> Run as Administrator). Each line corresponds to one command.

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade

Whether the update was successful can be tested with the following command.

npm -v

Update Node.js on Linux and macOS (OS X)

Each line is to be issued as a single command:

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

Whether the update was successful can be tested with the following command.

node -v

Update Node.js on Windows

The following commands have to be set in Powershell (Start -> “powershell” -> right click -> Run as Administrator). Each line corresponds to one command.

Install-Module -Name power-nvm
Add-Type -AssemblyName System.IO.Compression.FileSystem
nvm install latest
nvm default latest

Alternatively, only the Node.js binary can be exchanged via WGET. Should you use the 32-bit (x86) variant, this is done with the following command:

wget https://nodejs.org/download/release/latest/win-x86/node.exe -OutFile 'C:\Program Files (x86)\nodejs\node.exe'

For the 64-bit (x64) variant, the following command must be used:

wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'

Whether the update was successful can be tested with the following command.

node -v

If the Powershell script shown above does not work anymore, Node.js can also be updated “manually”. All you have to do is download the latest version from the Node.js page and then install it over the current version.

To update Node.js using the command prompt (cmd), you can utilize the Node Version Manager (nvm) or simply reinstall the latest version; below is the command for updating via nvm:

nvm install latest

Understanding Node.js and CMD

What is Node.js?

Node.js is a JavaScript runtime built on Chrome’s V8 engine. It allows developers to execute JavaScript code on the server side, enabling the development of scalable network applications. With its non-blocking, event-driven architecture, Node.js is particularly well-suited for building applications that require real-time interaction and data-intensive workloads. In today’s fast-paced digital environment, keeping Node.js updated ensures you leverage the latest performance improvements and security patches.

What is CMD?

The Command Line Interface (CLI), commonly referred to as CMD in Windows, is a powerful tool that lets users execute commands directly to manage system tasks and software applications. Utilizing CMD while working with Node.js simplifies various operations, including package management and running scripts.

Update Time Cmd Made Easy: A Quick Guide

Update Time Cmd Made Easy: A Quick Guide

The Basics of Updating Node.js

Why Update Node.js?

Updating Node.js is crucial for several compelling reasons:

  • Security Updates: New vulnerabilities are discovered regularly, and updates often include patches to keep your applications secure from threats.
  • New Features: Each release of Node.js may come packed with new features that enhance your development workflow and allow you to implement better functionalities in your applications.
  • Performance Enhancements: Updates typically include optimizations that can lead to better resource management and overall performance.

Methods to Update Node.js

Using Node Version Manager (NVM)

NVM (Node Version Manager) is a highly recommended tool for managing Node.js versions. This tool allows you to easily switch between different versions, making the update process seamless.

Installation Instructions:

To install NVM on your system, you can follow the steps outlined in the official NVM documentation. It’s typically as easy as running a curl or wget command in your CMD terminal.

Updating Node.js with NVM:

  1. To list available Node.js versions, use the command:

    nvm list available
    

    This command will display all the Node.js versions that you can install.

  2. To install a specific version, run:

    nvm install <version>
    

    Replace `<version>` with the desired version number, such as `16.13.0`.

  3. To set a default version, execute:

    nvm alias default <version>
    

    This command will set the specified version as the default version for your Node.js environment.

Updating via Node.js Installer

If you prefer a straightforward approach, you can download the official Node.js installer from the [Node.js website](https://nodejs.org/).

To run the installer:

  • Simply download the installer executable for your operating system.
  • Once downloaded, open CMD, navigate to your downloads directory, and run the installer by typing the file name, e.g., `node-v16.13.0-x64.msi`. This will guide you through the installation process and update Node.js to the latest version.

Updating via CMD (for Advanced Users)

For users who are comfortable with the command line, npm can facilitate the update of Node.js.

  1. To update npm itself, use the following command:

    npm install -g npm
    

    This will ensure your npm is up-to-date.

  2. To update Node.js using npm, you can run:

    npm install -g node
    

    Though this method is less common, it can be effective if you are already comfortable with npm.

Mastering Gp Update Cmd for Quick System Refreshes

Mastering Gp Update Cmd for Quick System Refreshes

How to Check the Current Node.js Version

Checking Version from CMD

To verify the currently installed version of Node.js, you can execute the following command in CMD:

node -v

This will give you a clear output of your Node.js version, such as `v16.13.0`. Keeping track of this information is essential, especially after an update.

Verifying npm Version

Additionally, ensuring that your npm is also up-to-date is vital for harmonious operation with Node.js. You can check the npm version using this command:

npm -v

Receiving an output similar to `8.1.0` indicates your version of npm that complements your installed Node.js.

Prank Cmd: Fun Commands to Play on Friends

Prank Cmd: Fun Commands to Play on Friends

Troubleshooting Common Issues

Common Issues During Update

When updating Node.js, you may encounter common issues:

  • Stale Cache Problems: Sometimes, a stale npm cache can cause conflicts during updates. To address this, you can clear the cache using:
    npm cache clean --force
    
  • Permission Errors: If you encounter permission errors, it may be due to insufficient access rights on your machine. Consider running your commands with administrator privileges or following proper permission settings for CMD.

Verifying the Update

After executing your update, it’s critical to confirm that it was successful. Repeat the commands to check the versions:

node -v

and

npm -v

If both outputs reflect the updated versions, you can proceed confidently. In some cases, additional tools or packages may help monitor performance, especially in production environments.

Create Folders Cmd Like a Pro: A Quick Guide

Create Folders Cmd Like a Pro: A Quick Guide

Conclusion

Regularly updating Node.js through CMD is essential for enhancing security, unlocking new features, and optimizing performance. By using tools like NVM or the Node.js installer, developers can streamline the management of their development environments. Continuous learning about Node.js and CMD commands will further improve your development practices, making you a more efficient programmer.

Trace Rout Cmd: Mastering Your Network Path in Cmd

Trace Rout Cmd: Mastering Your Network Path in Cmd

Additional Resources

To enhance your understanding and capabilities, consider exploring the following resources:

  • Official Node.js Documentation for in-depth knowledge.
  • NVM Documentation for better management of Node.js versions.
  • Video tutorials on platforms like YouTube that can provide visual guidance.

Rename Folder Cmd: A Quick Guide to Mastering It

Rename Folder Cmd: A Quick Guide to Mastering It

Call to Action

If you found this guide helpful, be sure to subscribe for more tips and tricks on CMD and Node.js. Joining a community forum or group can also provide additional support and knowledge sharing among fellow Node.js enthusiasts.

испробованы следующие способы:
1.npm cache clean -f
npm install -g n
n latest
2. npm install -g npm-windows-upgrade
npm-windows-upgrade
не помогло


  • Вопрос задан

  • 5547 просмотров



1

комментарий


Подписаться

1



Простой


1

комментарий


Решения вопроса 1

Удобнее всего установить NVM и управлять версиями через него, в любой момент можно поставить последнюю версию или переключится на любую предыдущую..

Пригласить эксперта


Ваш ответ на вопрос

Войдите, чтобы написать ответ


Похожие вопросы


  • Показать ещё
    Загружается…

Минуточку внимания

Реклама

Node.js is an extremely vast, server-side open-source JavaScript environment that runs on Chrome’s V8 JS engine. This enormousness of Node.js has resulted in a huge and active community of users, flooding contributions every second.

Node.js is an emerging technology and it provides regular updates, it is essential to keep updating to the latest versions of Node to follow up with the community and upcoming documentation.

The new versions come with more enhanced security, introducing better features considering the increasing threats and changing demands out there.

In this tutorial, we will walk you through various ways of updating Node.js on MacOS, Windows and Linux.

Also Read: How to Build and Publish a NPM Package

Check the version of Node.js

Before we begin, let’s start by checking our version of Node.js, like this:

or

Different Ways to Update Node on macOS

1. npm

NPM(node package manager) is an online open-source repository for publishing Node.js projects. It is also a command-line utility for interacting with those repositories and helps in package installations.

If you are a MacOS user, this simple update method of using npm for Node.js update is relevant for you.

To update Node.js via the command line, we can use a tool called n in the npm command. This will help us interact with different versions of Node.

Let us first clear any cache that’s present:

Installing n globally:

Now that we have n installed, let’s install the latest stable version of Node:

You may even choose to install the latest features by:

To download a specific version, you can simply do this:

2. Homebrew

Homebrew is made for MacOS and is a popular package management tool. We can use it to update the version of Node.js on our Mac machine.

Start by running this command in our MacOS terminal:

Update Homebrew before updating Node, run:

Update node:

To easily switch between Node.js versions:

nvm-windows

We can make use of the nvm-windows and NVM(Node Version Manager) tool to update Node version windows. Although there are several usage similarities, NVM and nvm-windows aren’t the same.

It is required that you uninstall any existing Node and npm versions, otherwise, there’s a chance for versions to conflict. Make sure you also delete any existing installation directories for example (%ProgramFiles%\nodejs)

Click here to download the nvm-setup.zip file and run the latest installer.

Now, jump to your Command Prompt or PowerShell terminal. Remember to Run it as Administrator because the utility runs in an Admin shell.

Start by installing the LTS (long-term supported) version, let’s say we want to install 14.17.1:

Next, switch to the version you just installed:

Or, you can choose to simply install whatever is the latest version:

To view a list of installed Node.js versions, run this:

To view a list of versions available for download, run this:

Different Ways to Update NodeJS on Linux (or macOS)

1. Node Version Manager

A Node version manager is a tool or a utility that enables developers to install different versions of Node.js and switch impeccably between them.

There are two Node version managers to choose from for Linux or MacOS, nvm or n.

nvm

nvm is nothing but a script-based version manager of Node.js. You can update your version of Node.js on Linux or MacOS with Wget or cURL.

Let’s say we want to install the v0.38.0 of nvm, in this example.

To update with Wget, run this command:

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

To update with cURL, run this command:

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

These commands will also let you clone the repo to ~/.nvm in a way to let you make changes to your bash profile and gives you access to nvm globally around your system.

Let us check if the installation was successful:

If installed properly, it will spit out nvm.

n

We have already seen how we can upgrade Node.js on MacOS with n. These steps that follow are for Linux.

Let us first clear any cache that’s present:

Installing n globally:

Now that we have n installed, let’s install the latest stable version of Node:

You may even choose to install the latest features by:

To download a specific version, you can simply do this:

To see a list of downloaded versions on your machine:

To upgrade to the latest LTS version:

Updating NodeJS using a Node Installer

Although this is the least recommended way to perform a version update for Node.js, it is still a possible solution if for some reason you face issues with any steps above.

Node Installers Win Mac Linux

Updating Node.js with Installer on Linux

Simply jump to the downloads page where you will find many Linux binary packages. Select your preferred installer.

Updating Node.js with Installer on Windows & macOS

Based on your system, you can select from any of the two highlighted installers for Windows and macOS.

Run the installation wizard. Normally, there’s nothing of the defaults that you would have to change.

After you’re done, it will have flawlessly completed installing Node.js and upgrading your version of Node.js by replacing it with the new one.

Summary

Node.js is updating regularly to provide better security, new features and more stability. When a new version is presented, the documentation is also updated, and to follow up on that documentation you must install the latest version. For example, if you are using an old version and try to access a method by reading the documentation of the latest version will cause an error. So updating to the latest version is a great way to solve this conflict. We hope this tutorial helps you update to the latest version of Node.js on your respective operating system.

Reference

https://nodejs.org/en/download/

Node.js is updating quite frequently these days, so using your terminal on a Mac or command line on Windows would make update process faster.

Updating Node.js on a Mac

To update node.js on a mac, through terminal, you have a lot of options through popular package managers or node.js version managers.

N

N is a very simple node.js version management system. If you don’t have it, you can install it:

$ npm install -g n

To update to the latest node.js version, you can run the following command:

sudo n latest

Homebrew

Homebrew is a package manager for Mac. If you don’t have it, your can install it:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

If you haven’t installed node through brew you can do it using this command:

brew install node

To update to the latest node.js version, you can run the following command:

brew update
brew upgrade node

Nvm

Nvm is a script-based node version manager. If you don’t have it, your can install it:

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

or with wget

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

To update to the latest node.js version, you can run the following command:

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

Updating Node.js on Windows

For Windows, the options are not that many, but still you can do it through command line.

NVM for Windows

Nvm is a Node Version Manager for windows, that allows you to manage multiple installations of node.js on a Windows computer. If you don’t have it, you need to download an installer the first time.

After you have completed installation, you can update to the latest node.js version through the following command:

nvm install latest

nvm-install-latest-node.js

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Английская раскладка при загрузке windows 10
  • Как отключить turbo boost в windows 10 на пк
  • Можно ли запустить fallout 3 на windows 10
  • Эмулятор телевизора для windows
  • There is a problem with this windows installer package перевод