-
安装
nvm
:curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
-
创建
.nvmrc
文件:echo "22.6.0" > .nvmrc
-
在
~/.zshrc
或~/.bashrc
或~/.oh-my-zsh/custom
目录中新建一个nvmrc.zsh
文件中添加下面的内容:check_nvm_installed() { if ! command -v nvm &> /dev/null; then return 1 fi return 0 } # load the nodejs specified in the .nvmrc autoload_nvmrc() { if check_nvm_installed; then if [ -f .nvmrc ]; then nvm use fi fi } # hook function, will be excuted whenever enterring a dir if [ -n "$ZSH_VERSION" ]; then # Zsh autoload -U add-zsh-hook add-zsh-hook chpwd autoload_nvmrc autoload_nvmrc elif [ -n "$BASH_VERSION" ]; then # Bash PROMPT_COMMAND="autoload_nvmrc;$PROMPT_COMMAND" fi
或参考:https://github.com/nvm-sh/nvm#zsh
如果是在
~/.oh-my-zsh/custom
下创建文件,需要把以下 nvm 初始化的内容放到~/.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
-
重新加载
shell
的配置文件source ~/.zshrc # 如果使用的是 Zsh # 或 source ~/.bashrc # 如果使用的是 Bash
Last active
November 8, 2024 10:10
-
-
Save aispin/0c3fc47b417e93959f9473d1c2f739ff to your computer and use it in GitHub Desktop.
NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tips on using NodeJS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment