Appearance
Linux 下 Nodejs 安装
- 下载 Nodejs
1.1 下载
shell
# 前置 进入/usr/local/software文件夹
cd /usr/local/
mkdir ./software
cd ./software
wget https://nodejs.org/dist/v12.18.4/node-v12.18.4-linux-x64.tar.xz
解压
shell
tar -xvf node-v12.18.4-linux-x64.tar.xz
1.2 验证 Node
shell
./bin/node -v
- 移动到/usr/local/node 目录
shell
## /usr/local/node/bin/node 这个路径是node.js解压包的路径,重新起了个名字
mv /usr/local/software/node-v12.18.4-linux-x64 /usr/local/node // 修改解压包名称
- 配置软连接,使全局都可以使用 node 命令
shell
ln -s /usr/local/node/bin/node /usr/bin/node --将node源文件映射到usr/bin下的node文件
ln -s /usr/local/node/bin/npm /usr/bin/npm
3.1 验证软连接
shell
node -v
npm -v
- 配置 node
进入 /usr/local/node 路径
shell
mkdir node_global
mkdir node_cache
npm config set prefix "node_global"
npm config set cache "node_cache"
4.2 配置淘宝源
shell
npm config set registry https://registry.npm.taobao.org
# 验证
npm config get registry
yarn
问题
- 磁盘空间
yarn的缓存会占用很大的空间,需要将缓存地址配置到大数据文件夹
shell
df -h
du -sh *
yarn config get cache-folder
# 修改成其他的地址
yarn config set cache-folder /usr/xxx