# ubuntu 下安装 node > ubuntu 20.04 > 适用版本 ubuntu18 - 22 应该吧 ## 安装步骤 ### 首先确保更新软件库 ```shell sudo apt update ``` ### 1. 获取`node`与`npm` > 这一步应该只安装一个`npm`就够了,没试过,可以尝试 安装`npm` ```shell sudo apt-get install npm ``` 安装`nodejs` ```shell sudo apt-get install nodejs ``` ### 2. 通过`npm`安装`n` > 防止网络异常, 先配置镜像源. 目前在腾讯云的轻量服务器上遇见了这一问题 > 这部分记得使用`sudo`运行 ```shell npm config set registry https://registry.npmjs.org ``` ```shell sudo npm install -g n ``` ### 3. 使用`n`安装最新稳定版本`node` ```shell sudo n latest ``` ### 5. 移除`node`与`npm` 卸载`npm` ```shell sudo apt-get autoremove npm ``` 卸载`nodejs` ```shell sudo apt-get autoremove nodejs ``` ### 重新打开终端 刚操作完, 可能会有缓存,所以需要重新连接一下终端, 刷新缓存 ### 检验版本 ```shell node -v npm -v ``` ## n 模块使用方法 ### 安装指定版本node ```shell n 版本号 ``` 版本号可以为 `latest` 和 `lts` 如果是需要指定版本的话则为 v版本数字 ## 方法解释 在`ubuntu`中的`apt`仓库内的node版本太老旧, 但是可以使用`npm`来全局安装`node`版本管理工具来管理node版本 安装完`n`后就可以卸载掉通过`apt`安装的`node`,使用`n`来管控