正在进入ing...

mac下安装npm及设置淘宝镜像

发布时间:2020-09-08 浏览量: 5957 文章分类: 前端相关

前端小白,自学Vue的时候,看到官方教程里面有Vue CLI脚手架,虽然暂时不知道是啥,但是查询看到这个玩意貌似能省事不少,而且本身前端就乱七八糟的。这里就记录一下安装的过程

安装Node.js

先去官方网站https://nodejs.org/zh-cn/download/下载对应的包,我是mac直接选择苹果图片下载,然后一直继续就可以安装上了,安装完毕后,在终端尝试一下 下面2个命令看看是否正确。

node -v  (输入)
--> v12.18.3  (输出)
npm -v (输入)
--> 6.14.6(输出)

如果现实上面2个就算OK了~

设置镜像

因为我们有万能的“墙”,所以这类安装最好还是把镜像设置到我们国内,这样在安装的时候速度更快,也能少很多幺蛾子。 npm install -g cnpm --registry=https://registry.npm.taobao.org

不知道哪里设置了什么,我的电脑安装老出现下面这样的错误,一直提示权限不对,老被拒绝,各种折腾都不行,那既然这里访问有问题,那就让文件换个地方吧。

sudo chown -R $USER /usr/local/lib/node_modules 执行后OK~

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
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! A complete log of this run can be found in:
npm ERR!     /Users/zj/.npm/_logs/2020-08-03T05_14_26_110Z-debug.log

常用命令(持续更新)

npm cache clean --force 清空npm缓存 npm i 重新安装

安装Vue-Cli

npm install -g @vue/cli # 安装的是3.0 npm install -g vue-cli # 安装2.x的版本

关于构建项目很么的,等我后续搞明白了,会在出一篇文章记录