During development, it is common to run into problems with node versions that are too high, so you want to install a lower version of Node and start the node download journey.
– Download and install NVM
Check to see if you have NVM. If you have NVM, you can use the NVM install version number. If not, go to the official website to find the following command to execute.
The curl - o - https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash or wget -- qO https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bashCopy the code
If an error occurs while installing NVM, you can configure one of the.zshrc or.bash_profile files in the root directory ~
Bash_profile (3) I (4) then copy and paste the following configuration: esc -> :wq! export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" (5) source.bash_profile to take effect (6) Re-download NVMCopy the code
After downloading NVM, I quickly installed Node.
But it’s not as simple as I thought. After numerous attempts to install the NVM version number, errors have been reported. Despair ~ ~ ~
However, node versions under 15.* cannot be installed on m1-chip systems because arm 64 does not precompile NodeJS binaries.
January 2021: there are no pre-compiled NodeJS binaries for versions prior to 15.x for Apple’s new M1 chip (arm64 architecture).
When using NVM to download node, c++ will compile successfully, but still report out of memory error.
- using
nvm
to install, say,v14.15.4
:- the C code compiles successfully
- but crashes with an out of memory error when used
- increasing the memory available to node still produces the out of memory errors:
- when using
nvm
to install some versions, the compilation fails
– Solution
According to the official website, his solution was to change the shell architecture from ARM64 to x86.
Arch arm64 # This confirms that ARCH is for M1 chips and is the cause of the problem. # So we need to uninstall it. $NVM uninstall v14.15.4 # Start the ZSH process on the 64-bit X86 architecture: $arch-x86_64 ZSH # Install the node using NVM, which will download the precompiled x64 binaries: Arch x64 # can now safely return to the arm64 ZSH process: $exit # We are back to the native shell: $NVM Use v14.15.4 Now Using node v14.15.4 (NPM v6.14.10)Copy the code
– Set the default version
After installing NVM in the above way, the node version will be changed, but when you open VScode, the version will be changed, so you can set the default version
nvm alias default version
Copy the code