Ubuntu 平台直接 get install nodejs
,安装的版本可能与官方最新版相距甚远,我一个月之前安装的,是 8.1.0,而官网最新 LTS 版本已是 16.13.1,参考了网上的教程,给出安装最新版的方法:
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
# Install Yarn
sudo apt-get install gcc g++ make
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
# 安装最新版 Node.js
sudo apt-get install -y nodejs
node -v
v16.13.1
即告成功,开始编程:
var person = new Object();
person.name = "Resin";
console.log(person.name);
// What's the result?
var user = "Progammer";
user.name = "Resin";
console.log(user.name);
// And this time?
安装 Yarn
在本次安装之前,我只知道 Node.js 的包管理工具是 npm,太有名气了,但新宠却是 Facebook 发布的 Yarn。在我更新 Node.js 安装源的时候,系统已提示,只是当时没有在意。
安装命令:
sudo apt update
Hit:1 http://mirrors.aliyuncs.com/ubuntu bionic InRelease
Get:2 http://mirrors.aliyuncs.com/ubuntu bionic-security InRelease [88.7 kB]
Get:3 http://mirrors.aliyuncs.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://mirrors.aliyuncs.com/ubuntu bionic-proposed InRelease [242 kB]
Get:5 http://mirrors.aliyuncs.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:6 https://dl.yarnpkg.com/debian stable InRelease [17.1 kB]
Hit:7 https://deb.nodesource.com/node_16.x bionic InRelease
Get:8 https://dl.yarnpkg.com/debian stable/main amd64 Packages [10.5 kB]
Get:9 https://dl.yarnpkg.com/debian stable/main all Packages [10.5 kB]
Get:10 https://dl.yarnpkg.com/debian stable/main i386 Packages [10.5 kB]
Fetched 543 kB in 3s (207 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
271 packages can be upgraded. Run 'apt list --upgradable' to see them.
sudo apt install --no-install-recommends yarn
yarn -v
1.22.17
作为 Node.js 的传统搭伴,npm 也在系统中安装了,版本也从未更新源的 3.5.2 升级到 8.1.2。另外,发现 Node.js 最新版,在 REPL 模式下,会有自动提示。
Yarn 常用命令:
mkdir ~/test_project && cd ~/test_project
yarn init test_project
yarn add [package_name]
yarn add [package_name]@[version_or_tag]
yarn upgrade
yarn upgrade [package_name]
yarn upgrade [package_name]@[version_or_tag]
yarn remove [package_name]
想要安装 package.json
文件中指定的所有项目依赖,运行 yarn
或者 yarn install
即可。
1 条评论
如果止步于此,就不是真正的学习!