linux ubuntu安裝node npm cnpm nvm nrm yarn vue-cli vue-router


linux ubuntu安裝node npm cnpm nvm nrm yarn vue-cli vue-router

一.安裝node

1.下載node
打開網址:http://nodejs.cn/download/

linux安裝node

復制下面的連接

cd /usr/local
wget https://npm.taobao.org/mirrors/node/v12.14.1/node-v12.14.1-linux-x64.tar.xz  //下載
tar -xf node-v10.15.0-linux-x64.tar.xz //2.解壓
cd nnode-v12.14.1-linux-x64

2.配置全局變量

sudo vim /etc/profile

PATH=$PATH:/usr/local/node-v12.14.1-linux-x64/bin

3.更新配置文件

source /etc/profile

在子賬號和root賬號的~/.bashrc文件里都加入source /etc/profile

vim ~/.bashrc

加入source /etc/profile
保存退出

4.打印版本.

root@haima-PC:/home/haima/go/src/gin-admin-react# npm -v
6.13.4
root@haima-PC:/home/haima/go/src/gin-admin-react# node -v
v12.14.1

windows安裝node

可以參考下面連接
https://www.jianshu.com/p/13f45e24b1de

  1. 下載zip安裝包

  2. 解壓到下面
    D:\Program Files (x86)\node-v12.16.2-win-x64

3.添加環境變量

4.cmd里打印版本,已經安裝成功了。

二.安裝nvm(選裝)

nvm全名node.js version management,顧名思義是一個nodejs的版本管理工具。
通過它可以安裝和切換不同版本的nodejs。
nvm和n都是node版本管理工具
為了解決node各種版本存在不兼容現象
nvm是讓你在同一台機器上安裝和切換不同版本的node的工具

github地址:
https://github.com/nvm-sh/nvm

安裝:

$ mkdir -p /usr/local/nvm

$ git clone https://github.com/nvm-sh/nvm.git /usr/local/nvm

$ cd /usr/local/nvm

//安裝
$ ./install.sh 
//添加淘寶鏡像地址
$ export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/dist 
//重啟配置文件
$ source ~/.bash_profile

//安裝node.js
$ nvm install 10.16.2

命令:
nvm ls-remote:列出所有可以安裝的node版本號
nvm install v10.4.0:安裝指定版本號的node
nvm use v10.3.0:切換node的版本,這個是全局的
nvm current:當前node版本
nvm ls:列出所有已經安裝的node版本
nvm uninstall v10.4.0 //卸載

更多詳細:
https://www.cnblogs.com/gaozejie/p/10689742.html

三.安裝cnpm

taobao 源鏡像加速

下載安裝cnpm

完成npm的安裝后,再安裝cnpm

https://npm.taobao.org/

切換源為 taobao 源

npm set registry https://registry.npm.taobao.org/

安裝cnpm

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

打印版本

root@haima-PC:/home/haima/go/src/gin-admin-react# npm set registry https://registry.npm.taobao.org/  //切換源為 taobao 源
root@haima-PC:/home/haima/go/src/gin-admin-react# npm install -g cnpm --registry=https://registry.npm.taobao.org  //安裝cnpm
root@haima-PC:/home/haima/go/src/gin-admin-react# cnpm -v
cnpm@6.1.1 (/usr/local/node-v12.14.1-linux-x64/lib/node_modules/cnpm/lib/parse_argv.js)
npm@6.13.7 (/usr/local/node-v12.14.1-linux-x64/lib/node_modules/cnpm/node_modules/npm/lib/npm.js)
node@12.14.1 (/usr/local/node-v12.14.1-linux-x64/bin/node)
npminstall@3.27.0 (/usr/local/node-v12.14.1-linux-x64/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js)
prefix=/usr/local/node-v12.14.1-linux-x64 
linux x64 4.15.0-30deepin-generic 
registry=https://r.npm.taobao.org

四.安裝nrm

什么是nrm?
nrm 是一個 npm 源管理器,允許你快速地在 npm 源間切換。

https://blog.csdn.net/anway12138/article/details/79455224

npm install -g nrm //安裝
nrm -h //查看幫助命令
nrm ls //查看有哪些源
nrm use taobao //切換源

五.安裝yarn

cnpm install -g yarn //全局安裝yarn
查看版本:yarn --version 或者 yarn -v 
yarn config set registry https://registry.npm.taobao.org  //設置yarn的下載源為淘寶鏡像
yarn config get registry //查看鏡像是否切設置成功
yarn global add @vue/cli 全局安裝vue-cli腳手架
vue -V 或者 vue --version// 查看是否安裝成功 如果命令行有提示相應的版本信息則安裝成功
vue create 項目名稱 //在需要開發項目的路徑下打開命令行工具 就會自動創建一個項目文件夾創建腳手架項目

yarn命令 和npm對比

yarn / yarn install 等同於npm install 批量安裝依賴
yarn add xxx 等同於 npm install xxx —save 安裝指定包到指定位置
yarn remove xxx 等同於 npm uninstall xxx —save 卸載指定包
yarn add xxx —dev 等同於 npm install xxx —save-dev
yarn upgrade 等同於 npm update 升級全部包
yarn global add xxx 等同於 npm install xxx -g 全局安裝指定包

更多使用方法:

yarn的安裝和使用參考下面的文章

https://blog.csdn.net/yw00yw/article/details/81354533

六.安裝vue-cli

https://cli.vuejs.org/zh/guide/installation.html

全局安裝

npm install -g @vue/cliyarn global add @vue/cli

haima@haima-PC:~$ vue --version
@vue/cli 4.2.3
vue -h
vue ui

創建項目

https://blog.csdn.net/weixin_40688217/article/details/88321322

七.下載vue-router.js

https://router.vuejs.org/zh/installation.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM