# 1、node的安装 ## 1.1、官方版本安装 进入[node](https://nodejs.org/zh-cn/)官网下载安装包 安装选择下面选项 ![image-20210911173404485](../../照片/image-20210911173404485.png) ## 1.2、nvm(windows) windows 用户请下载安装[nvm-windows](https://github.com/coreybutler/nvm-windows) ```shell nvm install [arch]: The version can be a specific version, "latest" for the latest current version, or "lts" for the most recent LTS version. Optionally specify whether to install the 32 or 64 bit version (defaults to system arch). Set [arch] to "all" to install 32 AND 64 bit versions. Add --insecure to the end of this command to bypass SSL validation of the remote download server. nvm list [available]: List the node.js installations. Type available at the end to show a list of versions available for download. nvm on: Enable node.js version management. nvm off: Disable node.js version management (does not uninstall anything). nvm use [arch]: Switch to use the specified version. Optionally use latest, lts, or newest. newest is the latest installed version. Optionally specify 32/64bit architecture. nvm use will continue using the selected version, but switch to 32/64 bit mode. nvm node_mirror : Set the node mirror.People in China can use https://npmmirror.com/mirrors/node/ nvm npm_mirror : Set the npm mirror.People in China can use https://npmmirror.com/mirrors/npm/ 如果改源下载速度还是很慢的话可以尝试一下手动下载:[下载](https://blog.csdn.net/DW14687/article/details/122957949) ``` ## 1.3、n(linux) ```shell # 1.安装n curl -L https://git.io/n-install | bash # 2.安装node n 14 n lts ``` # 2、更改npm和yarn依赖包全局下载和缓存路径 1. 在 D盘新建一个目录,用来存放 npm 或 yarn 的 cache 和 依赖包文件 ```shell D:\node_package\npm D:\node_package\npm_cache D:\node_package\yarn D:\node_package\yarn_cache ``` 2. 更改npm 和 yarn 的配置 ``` # npm npm config set prefix "D:\node_package\npm" npm config set cache "D:\node_package\npm_cache" npm config set registry https://registry.npm.taobao.org/ # yarn yarn config set prefix "D:\node_package\yarn" yarn config set global-folder "D:\node_package\yarn" yarn config set cache-folder "D:\node_package\yarn_cache" yarn config set registry https://registry.npm.taobao.org/ ``` 3. 查看配置 ``` # npm npm config list # yarn yarn config list ``` 4. 为了让安装的包,能在控制台使用,需要配置 Path 环境变量 1) 新建 NODE_PATH 环境变量 ![image-20210911173714273](../../照片/image-20210911173714273.png) 2) 在 Path 中添加如下路径 ![image-20211130152530439](assets/image-20211130152530439.png)