Nodejs安装及环境配置(Nodejs installation and environment configuration)

1、下载安装
点击这里下载

根据自己电脑系统及位数选择,我这里选择windows64位.msi格式安装包

.msi和.zip格式区别:

.msi是Windows installer开发出来的程序安装文件,它可以让你安装,修改,卸载你所安装的程序。说白了.msi就是Windows installer的数据包,把所有和安装文件相关的内容封装在一个包里。
.zip是一个压缩包,解压之后即可,不需要安装
在这里插入图片描述
下载完成后,双击安装包,开始安装,一直点next即可,安装路径默认在C:\Program Files下,也可以自定义修改

在这里插入图片描述
在这里插入图片描述
npm package manager表示npm包管理器

online documentation shortcuts 在线文档快捷方式

Add to PATH添加node安装路径到环境变量

安装完成如图所示,这里我修改了node的安装路径C:\node

在这里插入图片描述
安装完成后,.msi格式的安装包已经将node.exe添加到系统环境变量path中,如果你下载的是.zip格式,因为没有安装过程,所以需要手动将node.exe所在目录添加到环境变量path中,查看系统变量验证

image.png

既然已经将node添加到全局系统变量,我们可以直接在CMD窗口中任意位置执行node,打开CMD窗口,执行命令node -v查看node版本
v14.7.0
最新版的node在安装时同时也安装了npm,执行npm -v查看npm版本

6.14.7
2、修改全局依赖包下载路径
默认情况下,我们在执行npm install -g XXXX下载全局包时,这个包的默认存放路径位C:\Users\用户名\AppData\Roaming\npm\node_modules下,可以通过CMD指令npm root -g查看

C:\Users\liaijie\AppData\Roaming\npm\node_modules
但是有时候我们不想让全局包放在这里,我们可以自定义存放目录,在CMD窗口执行以下两条命令修改默认路径:

npm config set prefix “C:\node\node_global”
npm config set cache “C:\node\node_cache”
或者打开c:\node\node_modules\npm.npmrc文件,修改如下:

prefix =C:\node\node_global
cache = C:\node\node_cache

以上操作表示,修改全局包下载目录为C:\node\node_global,缓存目录为C:\node\node_cache,并会自动创建node_global目录,而node_cache目录是缓存目录,会在你下载全局包时自动创建

在这里插入图片描述
3、配置环境变量
因为我们修改了全局包的下载路径,那么自然而然,我们下载的全局包就会存放在c:\node\node_global\node_modules,而其对应的cmd指令会存放在c:\node\node_global

我全局安装一个vue-cli脚手架

npm install @vue/cli -g
安装完成后:

在这里插入图片描述

在这里插入图片描述

我使用CMD命令vue create myproject指令创建一个项目,显示如下
‘vue’ 不是内部或外部命令,也不是可运行的程序
或批处理文件。
这是因为我们在执行指令时,它会默认在node安装根目录下查找指令文件,在这里就是vue.cmd,然后还会在node安装根目录下的node_modules下查找依赖包文件夹,在这里就是@vue文件夹,因为我们修改了全局包的存放路径,所以自然找不到了,所以我们需要把我们指定的全局包存放路径添加到系统环境变量,这样就可以找到了

在这里插入图片描述

再次测试:

C:\Users\liaijie>vue create myproject
? Your connection to the default npm registry seems to be slow.
Use https://registry.npm.taobao.org for faster installation? (Y/n)
OK,大功告成!!!!!

作者:月半小夜曲_
链接:https://www.jianshu.com/p/13f45e24b1de
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
转载Nodejs安装及环境配置

————————

1. Download and install
Click here to download

According to my computer system and number of bits, I choose windows 64 bit. MSI format installation package here

Differences between. MSI and. Zip formats:

. MSI is a program installation file developed by Windows Installer. It allows you to install, modify and uninstall the programs you install. To put it bluntly, MSI is the data package of Windows Installer, which encapsulates all the contents related to the installation files in one package.
. zip is a compressed package. You can unzip it without installing it
Insert picture description here
After downloading, double-click the installation package to start the installation, and click next. The installation path is under C: \ program files by default, or can be customized and modified

Insert picture description here
Insert picture description here
NPM package manager means NPM package manager

online documentation shortcuts 在线文档快捷方式

Add to path add the node installation path to the environment variable

The installation is completed as shown in the figure. Here I modified the installation path of node C: \ node

Insert picture description here
After installation, the installation package in. MSI format has added node.exe to the system environment variable path. If you download the. ZIP format, because there is no installation process, you need to manually add the directory of node.exe to the environment variable path to view the system variable verification

image.png

Now that node has been added to the global system variable, we can directly execute node anywhere in the CMD window, open the CMD window, execute the command node – V to view the node version
v14.7.0
NPM is also installed in the latest version of node. Run NPM – V to view the NPM version

6.14.7
2. Modify global dependent package download path
By default, when we execute NPM install – G XXXX to download the global package, the default storage path of the package is C: \ users \ user name \ appdata \ roaming \ NPM \ node_ Under modules, you can view it through CMD instruction NPM root – G

C:\Users\liaijie\AppData\Roaming\npm\node_ modules
However, sometimes we don’t want the global package to be placed here. We can customize the storage directory and execute the following two commands in the CMD window to modify the default path:

npm config set prefix “C:\node\node_global”
npm config set cache “C:\node\node_cache”
或者打开c:\node\node_modules\npm.npmrc文件,修改如下:

prefix =C:\node\node_global
cache = C:\node\node_cache

The above operations indicate that the global package download directory is modified to C: \ node \ node_ Global, the cache directory is C: \ node \ node_ Cache and automatically create node_ Global directory, not node_ The cache directory is a cache directory that will be created automatically when you download the global package

Insert picture description here
3. Configure environment variables
Because we have modified the download path of the global package, naturally, the global package we downloaded will be stored in C: \ node \ node_ global\node_ Modules, and the corresponding CMD instruction will be stored in C: \ node \ node_ global

I install a Vue cli scaffold globally

npm install @vue/cli -g
After installation:

Insert picture description here

Insert picture description here

I use the CMD command Vue create myproject command to create a project, as shown below
‘Vue’ is not an internal or external command, nor is it a runnable program
Or batch file.
This is because when we execute the instruction, it will find the instruction file in the root directory of node installation by default, here is vue.cmd, and then install node in the root directory of node_ Find the dependent package folder under modules, which is the @vue folder here. Because we modified the storage path of the global package, we can’t find it naturally. Therefore, we need to add the storage path of the global package we specified to the system environment variable so that we can find it

Insert picture description here

Retest:

C:\Users\liaijie>vue create myproject
? Your connection to the default npm registry seems to be slow.
Use https://registry.npm.taobao.org for faster installation? (Y/n)
OK,大功告成!!!!!

Author: Half Moon Serenade_
Link: https://www.jianshu.com/p/13f45e24b1de
Source: Jianshu
The copyright belongs to the author. For commercial reprint, please contact the author for authorization, and for non-commercial reprint, please indicate the source.
Reprint nodejs installation and environment configuration