Skip to content
官方QQ交流群
技术交流1:87208295   点此加入
技术交流2:787747122   点此加入
官网
云控制台
开放平台
关注微信公众号
代码仓库: 码云

node版本管理

描述

版本切换

依赖软件

  • fnm

查看版本

https://nodejs.org/dist/v20.18.0/

使用教程

sh

# 安装node 版本管理 fnm
curl -fsSL https://fnm.vercel.app/install | bash

# 更新配置
source ~/.profile
# 或
source ~/.bashrc

# 安装版本
fnm install 20  
fnm install 20.18  

# 使用版本
fnm use 20

# 删除版本
fnm uninstall 20

如果报错

error: We can't find the necessary environment variables to replace the Node version.
You should setup your shell profile to evaluate `fnm env`, see https://github.com/Schniz/fnm#shell-setup on how to do this
Check out our documentation for more information: https://fnm.vercel.app

查看你用的shell类型

sh
echo $SHELL

如果输出的是 /bin/bash 或 /usr/bin/bash,说明你正在使用 bash。 如果输出的是 /bin/zsh 或 /usr/bin/zsh,说明你正在使用 zsh。 如果输出的是其他路径(例如 /bin/fish),则说明你使用的是其他 shell,比如 fish。

找到你的配置文件,添加以下内容

sh
eval "$(fnm env --use-on-cd --shell bash)"

刷新配置

sh
source ~/.bash_profile

全局依赖问题

sh
mkdir -p ~/.npm_global
npm config set prefix ~/.npm_global
echo "export PATH=~/.npm_global/bin:$PATH" >> ~/.bash_profile
source ~/.bash_profile

https://zhuanlan.zhihu.com/p/587008009

参考

Copyright © 2017 10yun.com | 十云提供计算服务-IPV6 | ctocode组开发