002 Use npm to install vue3

After installing nodejs, it will come with the npm package management tool. We can use npm -v in cmd to check the npm version. Before installing vue, we need to set the npm global download package location because the default is in c disk, I want to change it to the nodejs directory, so go to the nodejs directory and create two directories, one cache and one global, then enter cmd and execute the following command to change the default location.

npm config set prefix “D:\Program Files\nodejs\node_global”

npm config set cache “D:\Program Files\nodejs\node_cache”

The picture below shows the path is set, but when querying, an error occurs, saying that the package cannot be read. In fact, the permissions are insufficient. We use the administrator to run cmd.

Press the win logo key, then enter cmd and click Run as administrator

If it still doesn't work, we can use cnpm for installation and other operations (it happens that we will also use cnpm when installing vue later)

Use the following command to install cnpm using Taobao mirror

npm install -g cnpm -registry=https://registry.npm.taobao.org

Since I have already installed it before, I added -f to force the installation again.

We can use cnpm -v to check the version

In fact, the syntax of cnpm and npm is basically the same.

Before officially entering the installation of vue, we need to set up npm first. Go to the environment variable and set NODE_PATH. The steps are as follows:

Right-click this computer, click Properties, then click Advanced System Settings on the left, then click Advanced, click Environment Variables, click New in System Variables, name the variable NODE_PATH, and set the variable value to the path of node_global, and then in NODE_PATH is referenced in Path. After the reference is completed, click OK to save until you return to the properties page.

After the environment variables are set, we need to reopen the CMD window to make the environment variables take effect (remember to run as an administrator). Let’s start installing vue below.

Use command

cnpm install -f -g vue@latest

@latest in this command means to install the latest version of vue, -g means global installation, which means that after installing this time, no matter how many vue projects you want to publish, -f means, even if you I have installed vue before, and now I need to reinstall it. Just wait until you see the prompt displayed at the bottom that all packages have been installed.

Guess you like

Origin blog.csdn.net/qq_45477065/article/details/126904227