您当前的位置: 首页 > 

彭世瑜

暂无认证

  • 0浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Node多版本管理工具NVM

彭世瑜 发布时间:2019-12-30 10:33:46 ,浏览量:0

nvm Node Version Manager

Vue:从单页面到工程化项目

切换Node版本
$ nvm list
        v8.17.0
->      v10.16.0
        v12.22.6
        system
         
$ nvm use 12.22.6
Now using node v12.22.6 (npm v6.14.15)
使用 .nvmrc切换Node版本

在目录下创建文件.nvmrc, 指定node的版本

$ echo '12.22.6' > .nvmrc

切换Node版本

$ nvm use
Now using node v12.22.6 (npm v6.14.15)
自动调用 nvm use

MacOS中在 ~/.bashrc 文件中添加一下代码段:

添加如下代码

## Automatically call nvm use
cdnvm() {
    command cd "$@";
    nvm_path=$(nvm_find_up .nvmrc | tr -d '\n')

    # If there are no .nvmrc file, use the default nvm version
    if [[ ! $nvm_path = *[^[:space:]]* ]]; then

        declare default_version;
        default_version=$(nvm version default);

        # If there is no default version, set it to `node`
        # This will use the latest version on your machine
        if [[ $default_version == "N/A" ]]; then
            nvm alias default node;
            default_version=$(nvm version default);
        fi

        # If the current version is not the default version, set it to use the default version
        if [[ $(nvm current) != "$default_version" ]]; then
            nvm use default;
        fi

        elif [[ -s $nvm_path/.nvmrc && -r $nvm_path/.nvmrc ]]; then
        declare nvm_version
        nvm_version=$(` and `*` characters and spaces
        # `locally_resolved_nvm_version` will be `N/A` if no local versions are found
        locally_resolved_nvm_version=$(nvm ls --no-colors "$nvm_version" | tail -1 | tr -d '\->*' | tr -d '[:space:]')

        # If it is not already installed, install it
        # `nvm install` will implicitly use the newly-installed version
        if [[ "$locally_resolved_nvm_version" == "N/A" ]]; then
            nvm install "$nvm_version";
        elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then
            nvm use "$nvm_version";
        fi
    fi
}
alias cd='cdnvm'
cd "$PWD"

添加指令

$ vim ~/.bashrc

# 添加完后让其生效
$ source ~/.bashrc

每次进入目录后,就会自动切换到指定的Node版本了

Now using node v12.22.6 (npm v6.14.15)

开机启动顺序:Linux:开机启动顺序启动顺序及配置开机启动

删除指定版本
nvm deactivate

nvm uninstall v4.2.3

cd ~/.nvm/versions/node
sudo rm -rf v4.2.3

参考 https://github.com/nvm-sh/nvm#bash https://stackoverflow.com/questions/39634954/nvm-uninstall-doesnt-actually-uninstall-the-node-version

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.1384s