Npm安装Vue


Npm安装Vue


正文

nodejs和npm的关系

node.js是javascript的一种运行环境,是对Google V8引擎进行的封装,是一个服务器端的javascript的解释器。

包含关系,nodejs中含有npm,比如说你安装好nodejs,你打开cmd输入npm -v会发现出现npm的版本号,说明npm已经安装好。

npm是nodejs的包管理器(package manager)。我们在Node.js上开发时,会用到很多别人已经写好的javascript代码, 如果每当我们需要别人的代码时,都根据名字搜索一下,下载源码,解压,再使用,会非常麻烦。于是就出现了包管理器npm。 大家把自己写好的源码上传到npm官网上,如果要用某个或某些个,直接通过npm安装就可以了,不用管那个源码在哪里。 并且如果我们要使用模块A,而模块A又依赖模块B,模块B又依赖模块C和D,此时npm会根据依赖关系, 把所有依赖的包都下载下来并且管理起来。试想如果这些工作全靠我们自己去完成会多么麻烦!

在 nodejs 官网下载安装包安装后,里面自带了 NPM。

Npm 安装 Vue

使用之前,我们先来掌握3个东西是用来干什么的:

  • npm: Nodejs下的包管理器。
  • webpack: 它主要的用途是通过CommonJS的语法把所有浏览器端需要发布的静态资源做相应的准备,比如资源的合并和打包。
  • vue-cli: 用户生成Vue工程模板(帮你快速开始一个vue的项目,也就是给你一套vue的结构,包含基础的依赖库,只需要 npm install 就可以安装)。

一、安装nodejs

在 nodejs 官网下载安装包安装,如安装在G:\WorkSoft\nodejs下。

查看版本:

C:\Users\zhuyi>node -v
v16.16.0

C:\Users\zhuyi>
C:\Users\zhuyi>npm -v
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
8.11.0

C:\Users\zhuyi>

二、设定全局位置

设定全局目录、缓存目录,如:

npm config set prefix “G:\WorkSoft\nodejs\node_global”

npm config set cache “G:\WorkSoft\nodejs\node_cache”

三、配置镜像站

npm config set registry=http://registry.npm.taobao.org

四、设定权限

nodejs的全局目录、缓存目录,需要设定用户的操作权限。

五、查看Vue信息

npm info vue

如:

C:\Users\zhuyi>npm info vue
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

vue@3.2.37 | MIT | deps: 5 | versions: 402
The progressive JavaScript framework for building modern web UI.
https://github.com/vuejs/core/tree/main/packages/vue#readme

keywords: vue

dist
.tarball: https://registry.npmmirror.com/vue/-/vue-3.2.37.tgz
.shasum: da220ccb618d78579d25b06c7c21498ca4e5452e
.integrity: sha512-bOKEZxrm8Eh+fveCqS1/NkG/n6aMidsI6hahas7pa0w/l7jkbssJVsRhVDs07IdDq7h9KHswZOgItnwJAgtVtQ==
.unpackedSize: 2.6 MB

dependencies:
@vue/compiler-dom: 3.2.37    @vue/runtime-dom: 3.2.37     @vue/shared: 3.2.37
@vue/compiler-sfc: 3.2.37    @vue/server-renderer: 3.2.37

maintainers:
- posva <posva13@gmail.com>
- yyx990803 <yyx990803@gmail.com>

dist-tags:
beta: 3.2.34-beta.1       latest: 3.2.37            next: 3.2.36              v2-beta: 2.7.0-beta.8
csp: 1.0.28-csp           legacy: 2.6.14            v2-alpha: 2.7.0-alpha.12  v2-latest: 2.7.4

published a month ago by yyx990803 <yyx990803@gmail.com>
npm notice
npm notice New minor version of npm available! 8.11.0 -> 8.13.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.13.2
npm notice Run npm install -g npm@8.13.2 to update!
npm notice

C:\Users\zhuyi>

六、安装Vue到全局目录

npm install vue -g

如:

C:\Users\zhuyi>npm install vue -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

added 21 packages in 4s

C:\Users\zhuyi>

七、安装vue-router到全局目录

npm install vue-router -g

如:

C:\Users\zhuyi>npm install vue-router -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

added 23 packages in 2s

C:\Users\zhuyi>

八、全局安装vue脚手架

npm install vue-cli -g

如:

C:\Users\zhuyi>npm install vue-cli -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm WARN deprecated vue-cli@2.9.6: This package has been deprecated in favour of @vue/cli

added 230 packages in 18s

C:\Users\zhuyi>

接着编辑环境编辑path。

新开命令行窗口,查看版本:

vue -V

如:

C:\Users\zhuyi>vue -V
2.9.6

C:\Users\zhuyi>

整体示例

示例命令:

C:\Users\zhuyi>npm list -global
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
C:\Users\zhuyi\AppData\Roaming\npm
`-- (empty)


C:\Users\zhuyi>
C:\Users\zhuyi>npm config set prefix "G:\WorkSoft\nodejs\node_global"
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

C:\Users\zhuyi>
C:\Users\zhuyi>npm config set cache "G:\WorkSoft\nodejs\node_cache"
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

C:\Users\zhuyi>npm list -global
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_39_21_047Z-debug-0.log'
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_39_22_880Z-debug-0.log'
G:\WorkSoft\nodejs\node_global
`-- (empty)


C:\Users\zhuyi>npm config set registry=http://registry.npm.taobao.org
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_40_27_986Z-debug-0.log'
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_40_29_011Z-debug-0.log'

C:\Users\zhuyi>
C:\Users\zhuyi>npm config list
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_40_46_860Z-debug-0.log'
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_40_47_963Z-debug-0.log'
; "builtin" config from G:\WorkSoft\nodejs\node_modules\npm\npmrc

; prefix = "C:\\Users\\zhuyi\\AppData\\Roaming\\npm" ; overridden by user

; "user" config from C:\Users\zhuyi\.npmrc

cache = "G:\\WorkSoft\\nodejs\\node_cache"
prefix = "G:\\WorkSoft\\nodejs\\node_global"
registry = "http://registry.npm.taobao.org/"

; node bin location = G:\WorkSoft\nodejs\node.exe
; node version = v16.16.0
; npm local prefix = C:\Users\zhuyi
; npm version = 8.11.0
; cwd = C:\Users\zhuyi
; HOME = C:\Users\zhuyi
; Run `npm config ls -l` to show all defaults.

C:\Users\zhuyi>
C:\Users\zhuyi>
C:\Users\zhuyi>npm config get registry
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_42_36_488Z-debug-0.log'
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_42_37_675Z-debug-0.log'
http://registry.npm.taobao.org/

C:\Users\zhuyi>
C:\Users\zhuyi>npm info vue
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_43_07_052Z-debug-0.log'
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_43_08_818Z-debug-0.log'
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path G:\WorkSoft\nodejs\node_cache\_cacache
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_cacache'
npm ERR!  [Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_cacache'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: 'G:\\WorkSoft\\nodejs\\node_cache\\_cacache'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! Log files were not written due to an error writing to the directory: G:\WorkSoft\nodejs\node_cache\_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

C:\Users\zhuyi>
C:\Users\zhuyi>
C:\Users\zhuyi>npm -v
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_49_43_751Z-debug-0.log'
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'G:\WorkSoft\nodejs\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'G:\WorkSoft\nodejs\node_cache\_logs\2022-07-10T08_49_44_959Z-debug-0.log'
8.11.0

C:\Users\zhuyi>
C:\Users\zhuyi>npm info vue
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

vue@3.2.37 | MIT | deps: 5 | versions: 402
The progressive JavaScript framework for building modern web UI.
https://github.com/vuejs/core/tree/main/packages/vue#readme

keywords: vue

dist
.tarball: https://registry.npmmirror.com/vue/-/vue-3.2.37.tgz
.shasum: da220ccb618d78579d25b06c7c21498ca4e5452e
.integrity: sha512-bOKEZxrm8Eh+fveCqS1/NkG/n6aMidsI6hahas7pa0w/l7jkbssJVsRhVDs07IdDq7h9KHswZOgItnwJAgtVtQ==
.unpackedSize: 2.6 MB

dependencies:
@vue/compiler-dom: 3.2.37    @vue/runtime-dom: 3.2.37     @vue/shared: 3.2.37
@vue/compiler-sfc: 3.2.37    @vue/server-renderer: 3.2.37

maintainers:
- posva <posva13@gmail.com>
- yyx990803 <yyx990803@gmail.com>

dist-tags:
beta: 3.2.34-beta.1       latest: 3.2.37            next: 3.2.36              v2-beta: 2.7.0-beta.8
csp: 1.0.28-csp           legacy: 2.6.14            v2-alpha: 2.7.0-alpha.12  v2-latest: 2.7.4

published a month ago by yyx990803 <yyx990803@gmail.com>
npm notice
npm notice New minor version of npm available! 8.11.0 -> 8.13.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.13.2
npm notice Run npm install -g npm@8.13.2 to update!
npm notice

C:\Users\zhuyi>
C:\Users\zhuyi>npm list -global
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
G:\WorkSoft\nodejs\node_global
`-- (empty)


C:\Users\zhuyi>
C:\Users\zhuyi>
C:\Users\zhuyi>npm install vue -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

added 21 packages in 4s

C:\Users\zhuyi>
C:\Users\zhuyi>
C:\Users\zhuyi>npm install vue-router -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

added 23 packages in 2s

C:\Users\zhuyi>
C:\Users\zhuyi>
C:\Users\zhuyi>
C:\Users\zhuyi>npm install vue-cli -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm WARN deprecated vue-cli@2.9.6: This package has been deprecated in favour of @vue/cli

added 230 packages in 18s

C:\Users\zhuyi>
C:\Users\zhuyi>npm list --global
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
G:\WorkSoft\nodejs\node_global
+-- vue-cli@2.9.6
+-- vue-router@4.1.1
`-- vue@3.2.37


C:\Users\zhuyi>npm list -global
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
G:\WorkSoft\nodejs\node_global
+-- vue-cli@2.9.6
+-- vue-router@4.1.1
`-- vue@3.2.37


C:\Users\zhuyi>






参考资料

Node.js 官网 https://nodejs.org/zh-cn/

NPM 官网 https://www.npmjs.com/

Node.js 教程 https://www.runoob.com/nodejs/nodejs-tutorial.html

vue.js中npm安装教程图解 https://www.jb51.net/article/138020.htm

Error: EPERM: operation not permitted, mkdir ‘D:\NodeJS\node_global‘,‘-4048’的解决方法 https://blog.csdn.net/weixin_44047784/article/details/123459192


返回