野声

Hey, 野声!

谁有天大力气可以拎着自己飞呀
twitter
github

Install nvm and nodejs

After seeing the artifact nvm online, I have been using nvm to install Nodejs recently.
Just installed Linux Mint, and reinstalled nvm on Linux. There is also a similar tool on Windows called nvm-windows, and the usage is similar.

GitHub link: https://github.com/creationix/nvm

nvm is a version control tool for nodejs, which stands for "Node Version Manager" in the first three letters.

Updated on 2019-06-29: Installing nvm on Windows

Installing nvm on Linux#

Installing and upgrading nvm#

To install or upgrade nvm, you can use the official script provided.

You can use curl:

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

Or wget:

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

If your machine is in China, raw.githubusercontent.com is blocked, you can use the reverse proxy provided by fastgit.org: https://raw.fastgit.org/.

wget -qO- https://raw.fastgit.org/creationix/nvm/v0.34.0/install.sh | bash

The current official version is v0.34.0.
You can install the latest version from the link provided above.
This script will clone the remote repository of nvm to the ~/.nvm path and add activation code to your terminal's configuration file.

After executing this command, everything is installed.
But in China, you still need to configure a proxy, which is not necessary if you don't need it.

Configuring git proxy#

I use electron-ssr locally, and the proxy address is socks5://127.0.0.1:1080.
Execute the following command to set the proxy for GitHub.

# Only for github.com
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080

# Cancel the proxy
git config --global --unset http.https://github.com.proxy

Note that this method does not support proxy for ssh. That needs to be configured separately. I won't go into detail here, I will write another blog post to explain how to configure ssh proxy.

The configuration on the command line will also modify the .gitconfig file in the user's directory. This applies to both Windows and Linux.

In other words, the same effect can be achieved by modifying ~/.gitconfig:

[http "https://github.com"]
        proxy = socks5://127.0.0.1:1080

Configuring terminal proxy#

Because the commands in the terminal do not use the system proxy, you can use software like proxychains4 to proxy the commands.

After configuring proxychains4, use:

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

to install.

Configuring zsh#

After installing nvm, I found that I only wrote the startup configuration to ~/.bashrc on my local machine, so I manually copied the configuration to ~/.zshrc.

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

Then execute source ~/.zshrc, and you're done.

Installing nodejs#

Configuring nvm download source#

Execute:

export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node

to set the download source to the domestic Taobao mirror.

Installing nodejs with nvm#

Execute:

# Install stable version of node
nvm install stable
# Install the latest version of node
nvm install node

That's it~

Basic usage of nvm#

See: https://github.com/creationix/nvm#usage

I only use a few commands myself, and actually only need to master these few commands:

nvm list # Show available versions
nvm install 10.10.0 # Install the corresponding version
nvm use 10.10.0 # Use the corresponding version
nvm which 10.10.0 # View the installation directory of the corresponding version

Configuring npm registry#

npm install -g mirror-config-china --registry=http://registry.npm.taobao.org

You can configure several domestic registries in one go~

That's All.

Installing nvm on Windows#

Download and install#

nvm-windows

Download the latest version of nvm-windows in Releases. If you downloaded nvm-noinstall.zip, you need to configure the environment variables.
Here I directly installed the setup version, and after installation, enter nvm in cmd. If it is displayed, the installation is successful.

Configuring domestic source#

nvm node_mirror https://npm.taobao.org/mirrors/node/
nvm npm_mirror https://npm.taobao.org/mirrors/npm/

You can set nvm to download and install from China.
See the previous section for installing nodejs: Configuring npm registry

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.