不安分的黑娃
踏踏实实,坚持学习,慢慢就懂了~

Nodejs安装

Node.js 是什么?

Node.js® 是一个基于 Chrome V8 引擎 的 JavaScript 运行时环境。

1. 官网

2. 下载地址

3. 参考文档

4. 安装步骤

4.1 Ubuntu 环境

参考文档:https://github.com/nodesource/distributions/blob/master/README.md#debmanual

4.1.1 移除旧版本 PPA

# add-apt-repository may not be present on some Ubuntu releases:
# sudo apt-get install python-software-properties
sudo add-apt-repository -y -r ppa:chris-lea/node.js
sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list
sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list.save

4.1.2 添加 NodeSource package signing key

KEYRING=/usr/share/keyrings/nodesource.gpg
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
# wget can also be used:
# wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
gpg --no-default-keyring --keyring "$KEYRING" --list-keys

4.1.3 添加期望版本 NodeSource repository

# Replace with the branch of Node.js or io.js you want to install: node_6.x, node_8.x, etc...
VERSION=node_8.x
# Replace with the keyring above, if different
KEYRING=/usr/share/keyrings/nodesource.gpg
# The below command will set this correctly, but if lsb_release isn't available, you can set it manually:
# - For Debian distributions: jessie, sid, etc...
# - For Ubuntu distributions: xenial, bionic, etc...
# - For Debian or Ubuntu derived distributions your best option is to use the codename corresponding to the upstream release your distribution is based off. This is an advanced scenario and unsupported if your distribution is not listed as supported per earlier in this README.
DISTRO="$(lsb_release -s -c)"
echo "deb [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
echo "deb-src [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list

4.1.4 更新包列表并且安装 Node.js

sudo apt-get update
sudo apt-get install nodejs

4.2 CentOS7 环境

4.2.1下载安装包

安装包下载地址:https://nodejs.org/zh-cn/download/
image

这里我选择下载 Linux 64位版本
image

4.2.2 安装包上传到服务器

将 node-v16.13.0-linux-x64.tar.xz 上传至服务器。

4.2.3 解压安装包

(1) 将 node-v16.13.0-linux-x64.tar.xz 解压为 node-v16.13.0-linux-x64.tar
解压命令:

xz -d node-v16.13.0-linux-x64.tar.xz

(2) 将 node-v16.13.0-linux-x64.tar 解压
解压命令:

tar -xvf node-v16.13.0-linux-x64.tar

4.2.4 验证

 ## 切换到 安装bin目录下
 cd /opt/nodejs/node-v16.13.0-linux-x64/bin
  ## 查看npm版本
 ./npm -v

image

4.3 windows7 环境

4.3.1下载安装包

安装包下载地址:https://nodejs.org/zh-cn/download/
选择 Windows 安装包 64 位版本。
我这里的版本是 node-v16.13.0-x64.msi

4.3.2 安装

报错,提示 版本不适合windows7:
image

经百度,13.14.0是支持win7 的最后版本是 ,下载地址:https://nodejs.org/download/release/v13.14.0/

image

image

image

image

image

image

4.3.3 验证

打开 CMD 窗口,输入 node -v :
image

安装成功。

CMD 窗口,输入 “npm install npm -g” 命令可安装 npm。

5.使用 npm 安装js 包

https://www.npmjs.com/ 可以搜索应该下载的js包

# 在项目路径下安装 jquery
npm install jquery

image

设置 npm 国内镜像

# 设置 淘宝镜像
npm config set  registry https://registry.npm.taobao.org --global
npm config set  disturl https://npm.taobao.org/dist --global

# 恢复默认镜像 
npm config set  registry https://registry.npmjs.org 

image
没有报错,查看当前镜像:

# 查看当前镜像
npm get  registry 

image

4.3 Windows 11 环境

前面已经使用安装包安装了,这里采用免安装方式安装。

4.3.1 下载 Nodejs

安装版本(64位):https://nodejs.org/dist/v18.15.0/node-v18.15.0-x64.msi

免安装版本(64位):https://nodejs.org/dist/v18.15.0/node-v18.15.0-win-x64.zip

4.3.2 解压 node-v18.15.0-win-x64.zip

将 node-v18.15.0-win-x64.zip 解压到本地某个目录。我这里解压到本地:C:\work\soft\node-v18.15.0-win-x64

4.3.3 配置环境变量

将解压目录配置到环境变量:
image

然后将 NODEJS_HOME 配置到 PATH 中:
image
image

4.3.4 验证

打开 CMD 窗口,输入node -v 回车,输出“v18.15.0” 即安装完成。

posted on 2022-09-24 23:14  不安分的黑娃  阅读(2222)  评论(0编辑  收藏  举报