This is the 23rd day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021
preface
There are some bad tutorials on the Internet that don’t explain how to install NVM on a Mac to manage Node. As a result, beginners who are not familiar with the installation process will make a lot of mistakes and waste too much time installing NVM. For example, online tutorials do not explain how to view the configuration file.bash_profile in detail, so this blog will explain how to successfully install NVM on a Mac computer, for the convenience of those who need to check and use.
Note that if you want to install NVM on your Mac to manage NPM, you must make sure that Node is not installed on the Mac or uninstall the existing node version in advance. If you do not clean the Node version on your Mac in advance, the NVM installation will fail. The proper way to uninstall the installed version of Node from a Mac will be covered in a separate blog post. The reason for this blog post is that failing to cleanly remove Node from a Mac can cause some unforeseen errors.
Installation steps
The general steps for installing NVM are similar to those in the online tutorial, except that some points need to be noted in detail. The specific steps for installing NVM on a Mac are as follows:
1. Install the NVM
Open the Mac computer terminal, and then inside the terminal input command line: curl – o – raw.githubusercontent.com/creationix/… | bash enter, for installation
By default, a hidden file named.nvm will be created in the user folder on the Mac as follows:
Finder AppleShowAllFiles Yes && killall Finder: AppleShowAllFiles Yes && killall finder
Find AppleShowAllFiles No && killall Finder
Both commands are executed directly from the Mac terminal. Opening the hidden file will look like this:
2. Create and view the configuration file.bash_profile
Looking at the.bash_profile profile is one of the most important parts of installing NVM, because many people do not know how to create the steps to open the.bash_profile profile. It is actually very simple, but the tutorials on the Internet are not very good.
First open the.bash_profile file and check to see if it is in the.bash_profile folder. If it is not, copy it somewhere else to the.bash_profile folder. Then double-click on the.bash_profile file and add the following three lines:
Export NVM_DIR="/Users/Mac user name /.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_completionCopy the code
Note: In the above three lines, the user name to which NVM_DIR points can be viewed by searching “User folder” in Spotlight. The.bash_profile profile can be copied from another hidden file and changed to a.bash_profile name. The easiest way to do this is to copy the.bash_profile profile somewhere else.
3. Enable the configuration file.bash_profileTo take effect
For step 2, after putting three lines of code into the.bash_profile, the.bash_profile must be enabled, otherwise an error will be reported: NVM: command not found. The command line for enabling the.bash_profile is as follows:
source ~/.nvm/.bash_profile
4, summarize
After the above steps are described, NVM is successfully installed on the Mac, and you are now ready to manage the Node version on the Mac. Just be careful with a few caveats or the installation will fail.
The appendix,nvmCommon commands:
NVM ls: Prints all versions
NVM Install stable: Installs the most stable version
NVM install v10.16.0: Install node 10.16.0 (uninstall)
NVM current: node version in use
NVM use v10.16.0: Changes node to version 10.16.0
NVM alias Default 10.16.0: Sets the default node version to 10.16.0
NVM Alias Default: Sets the default Node version
NVM alias: Adds aliases to different version numbers
NVM unalias: Deletes the defined alias
NVM Scant-Packages: Reinstall the NPM package of the specified version globally in the current Node version environment
NPM install – g mz – fis: installation of mz – fis module to the global directory, install path: / Users/your Mac user name/NVM/versions/node/v0.12.7 / lib/mz – fis
NVM use 10.16.0: Switch to version 10.16.0 (support fuzzy query)
NPM install -g react-native cli: Install the react-native CLI module to the global directory. / Users/your Mac user name/NVM/versions/node/v4.2.2 / lib/react – native – cli
The last
The above is the method and steps of installing NVM in front end development. The knowledge point is not complicated. It is mainly unfamiliar to developers who just touch the front end development, so they need to know about it.
The above is all the content of this chapter. Welcome to pay attention to the wechat public account of Sanzhan “Program Ape by Sanzhan”, and the Sina Weibo account of Sanzhan “Sanzhan 666”, welcome to pay attention!