In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to install and manage multiple Node versions of NVM". The explanation in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "how to install and manage multiple Node versions of NVM".
We build projects that often require older versions of node. For example, the current supported version of Hexo is v12, while the latest stable version of Node is v14. At this point, to avoid bug, we need to switch to the Node version.
This tutorial applies to:
Linux (x86 architecture & ARM architecture)
MacOS (x86 architecture & ARM architecture)
Windows (X86 architecture, ARM architecture not tested)
Warning ⚠️: it is not recommended to use n modules under NPM to manage node versions
Environmental preparation
For different operating systems, we prepare different NVM tools. The following is the project address. If you are interested, you can go to the project source address. Ow:
For Mac/Linux: https://github.com/nvm-sh/nvm
For Windows: https://github.com/coreybutler/nvm-windows
Before configuring, please uninstall the Node version you have installed and the configured environment variables in advance to avoid conflicts.
Windows configuration method
There are two ways to configure NVM under Windows according to the configuration method of NVM project address:
Installer installation
Manual configuration (recommended)
The reason why it is not recommended to install NVM with an installer is that it is inconvenient to manage. There is essentially no difference between the two methods.
Opt1: installer
Enter the NVM-Windows project release address: github.com/coreybutler … Select the latest release nvm-setup.zip to download:
After that, extract the compressed file and click install:
Note here that ⚠️: the installation and configuration path of NVM should not be in Chinese, because our Windows virtual machine only allocates C disk, and you'd better install it to D disk and other user disks:
After the installation is complete, under CMD or Powershell, type NVM to find that the installation is complete:
Opt2: manually configure [push]
This is my recommended method. We download the NVM project file and configure it manually. Go to the project release address and download nvm-noinstall.zip:
Extract it into a blank file, and this folder is the NVM address directory. For example, my address here is: d:\ myEnvironment\ nvm
After that, find the computer's environment variables, such as Windows10: right-click this computer-Advanced system Settings-Environment variables:
Finally, add the environment variable:
NVM_HOME:NVM address directory, for example: d:\ myEnvironment\ nvm
NVM_SYMLINK:NVM configures a soft link for Node.js, which needs to point to a directory that does not exist (created automatically when NVM is used), such as D:\ myEnvironment\ nodejs
Append content to Path, append content:
% NVM_HOME%%NVM_SYMLINK%
After the installation is complete, under CMD or Powershell, type NVM to find that the installation is complete:
Configure domestic sources
It is a bit difficult for Chinese mainland to connect to the official Node.js and NPM servers, even if the download is slow and sometimes it cannot be downloaded and used directly. So we changed NVM and Node.js into domestic sources:
Go to your NVM installation path, open the setting.txt file (if not, just create it), and change:
Root: d:\ myEnvironment\ nvmpath: d:\ myEnvironment\ nodejsarch: 64proxy: nonenode_mirror: https://npm.taobao.org/mirrors/node/npm_mirror: https://npm.taobao.org/mirrors/npm/
Explain the parameters here:
The installation address of root:NVM. That is,% NVM_HOME% above
Path: the storage path when node.js is activated, that is,% NVM_SYMLINK% above
Arch: system architecture. If your Windwos is not x64, enter 32.
Proxy: whether to act as an agent or not
Download source for node_mirror:node.js
Download source for npm_mirror:npm
MacOS/Linux configuration method
Although you can install NVM using project package management tools (such as Homebrew, APT), it is recommended that macOS and Linux use manual configuration methods (Git installation, regular installation) to install NVM. This article also explains how to install NVM using a non-project package manager.
Opt1: official script
Official script, need to connect to Github, if your device can not effectively connect to Github, please choose another method (such as: regular installation, Git installation)
Terminal uses curl
Curl-o-https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Or use wget
Wget-qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Because the official project is still being updated, pasting scripts here may be out of date. It is recommended that you enter the official project address and paste it.
After installation, append to the environment variable according to the Shell you use:
Export NVM_DIR= "$HOME/.nvm" [- s "$NVM_DIR/nvm.sh"] &\. "$NVM_DIR/nvm.sh" # This loads nvm [- s "$NVM_DIR/bash_completion"] & &. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Generally, macOS is appended in ~ / .zshrc, and Linux is appended in ~ / .bashrc without manually configuring ZSH:
Finally, you can overload the environment variable configuration in Terminal:
# For macOS/Linux With ZSHsource ~ / .zshrc # For Linux With Bashsource ~ / .bashrc
If the terminal enters the nvm command, it will not report the command not find, for example:
Nvm-v
Opt2:Git installation
Git is also officially recommended for configuration, but it is still official to use Github. Domestic connections... So, I recommend using Gitee, typing in Terminal for the last time:
# enter the home directory cd ~ # download the source code git clone https://gitee.com/mirrors/nvm.git# and rename it to .nvmmv nvm .nvm
After we have installed NVM, we need to configure to the environment variable:
# Bash Shell user vim ~ / .profile # ZSH Shell user vim ~ / .zshrc
In the environment variable, append:
Export NVM_DIR= "$HOME/.nvm" [- s "$NVM_DIR/nvm.sh"] &\. "$NVM_DIR/nvm.sh" # This loads nvm
Finally, you can overload the environment variable configuration in Terminal:
# For macOS/Linux With ZSHsource ~ / .zshrc # For Linux With Bashsource ~ / .bashrc
If the terminal enters the nvm command, it will not report the command not find, for example:
Nvm-v
Opt3: general installation
A regular installation is actually a manual implementation of Opt1 or Opt2. Download the nvm source code manually and unzip it and rename it to .nvm. Finally, add the
Export NVM_DIR= "$HOME/.nvm" [- s "$NVM_DIR/nvm.sh"] &\. "$NVM_DIR/nvm.sh" # This loads nvm
Go to the environment variable and overload it.
Configure domestic sources
On the mainland side, the connection between Node and NPM sources is a bit busy, and NVM is also relatively slow, so we switch to domestic sources before using it. Temporary use: enter in the terminal
Export NVM_NODEJS_ORG_MIRROR= https://npm.taobao.org/mirrors/node/
If you need to use it for a long time, configure it in the configuration file.
Manage and install Node.js
Windows version and macOS/Linux version of NVM, the operation is basically the same, especially the command to manage Node.js
In this chapter, the mode of one step and two diagrams is adopted (one is the operation screenshot of the Windwos version of NVM, the other is the operation screenshot of the macOS/Linux version)
1. Check the version of nvm list
View the installed version:
two。 View installable version
How do I view the version of Node.js installed through NVM? You can use the NVM command directly:
# macOS/Linuxnvm ls-remote-lts# Windowsnvm list available
3. Install Node.js
We install v12.21 version node:
4. Activate the Node.js version
After we have installed Node.js, we need to activate
Nvm use 12.21
Test what can be used:
How to uninstall
If you need to uninstall the Node.js installed by NVM and NVM, it is also simple and there are no residual files.
Windwos
Windwos users, if installed with an installer, can use their own anti-installation shortcuts. Let's take a look at how the manual configuration method is uninstalled.
1. Delete NVM and Node.js soft links
The deleted address is the one during installation:
NVM_HOME:NVM address directory, for example: d:\ myEnvironment\ nvm
NVM_SYMLINK:NVM configures the soft chain of Node.js. For example: d:\ myEnvironment\ nodejs
two。 Delete environment variabl
After that: right-click this computer-Advanced system Settings-Environment variables:
Delete NVM_HOME, NVM_SYMLINK, and PATH above:
% NVM_HOME%%NVM_SYMLINK%
MacOS/Linux
MacOS and Linux are easier. Terminal executes:
# Delete NVM and Node.jsrm-rf ~ / .nvm # Delete possible NPMrm-rf ~ / .npn
Remove within the environment variable:
Export NVM_DIR= "$HOME/.nvm" [- s "$NVM_DIR/nvm.sh"] &\. "$NVM_DIR/nvm.sh" # This loads nvm [- s "$NVM_DIR/bash_completion"] & &. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
At this point, the NVM is uninstalled completely.
Operation example Hexo blog
When building a Hexo blog, it is best to use Node.js v12 for now (2021.07). So, when I set up a Hexo blog, I generally like to switch from Node.js to v12:
Minecraft panel
I'll dig a hole here, and then I'll have a chance to talk to you about how to use Node.js to compile the control panel of Minecraft.
VUE
Needless to say, there are just a few ways to install VUE. Installing VUE with Node.js 's package management tool NPM is perfectly normal and easy to run:
Thank you for reading, the above is the content of "how to install and manage multiple Node versions of NVM". After the study of this article, I believe you have a deeper understanding of how NVM installs and manages multiple Node versions, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.