前端环境搭建(nvm、nrm、yarn、git)

59 阅读1分钟

以下默认 linux 系统安装,其他系统待更新
持续更新相关内容


安裝 nvm (切换 node 版本)

github nvm

  • curl 方式
    ubuntu 安裝 curl sudo apt-get install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  • wget 方式
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

安裝成功提醒:重开一个新的命令行窗口

image.png

查看 nvm 版本: nvm -v 0.39.3


nvm 基本使用

首先查看下当前使用的 node 版本

nvm current

返回当前版本 18.16.0

image.png

再查看下目录下有哪些 node 版本,可以进行切换

nvm list

image.png

假设现在本地没有 20 版本的 node ,需要安装,则使用 nvm install xxx

nvm install 20.12.1

提示安装成功

image.png

然后切换到 20.12.1 版本

nvm use 20 # 或者写具体 20.23.1

如果某个项目需要长期使用 20 版本,可以使用 default 命令进行处理,default 命令生成的 alias 配置会存储在 nvm.sh 目录下,不用每次打开 terminal 输入 nvm use xxx 手动切换,只用设置一次即可自动适配。

nvm alias default 20.12.1

安装 git

install git in linux

sudo apt-get install git

验证是否成功: npm config get registry 返回镜像源地址


安装 yarn

npm install --global yarn

安装 nrm (切换 npm 源)

npm install nrm -g # 安装 nrm

nrm ls # 查看所有源
* npm ---------- https://registry.npmjs.org/
  yarn --------- https://registry.yarnpkg.com/
  tencent ------ https://mirrors.cloud.tencent.com/npm/
  cnpm --------- https://r.cnpmjs.org/
  taobao ------- https://registry.npmmirror.com/
  npmMirror ---- https://skimdb.npmjs.com/registry/
  
> nrm current # 查看当前源
You are using npm registry.

> nrm use tencent # 使用 Tencent 源

npm 设置镜像源

设置镜像 npm config set registry xxx
npm 源地址

http://mirrors.cloud.tencent.com/npm/ # 腾讯镜像
https://registry.npmmirror.com # 淘宝镜像
https://registry.npmjs.org/ # npm 原地址