1.安装nodejs和npm

 sudo apt-get install nodejs
 sudo apt-get install npm

测试nodejs的版本和包管理器npm的版本node --version、npm --version

2.进行nodejs版本升级

node有一个模块叫n,是专门用来管理node.js的版本的。

sudo npm install -g n

升级nodejs版本

 sudo n stable

3.升级npm版本

sudo npm install npm -g

4.进行版本查看

可以看到node的版本已经是最新版本了,但是npm版本查看的还是1.x.x

5.如果速度太慢,可以先改变npm的源

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

6.增加cnpm源

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

7.进行vue脚手架搭建

当然,这只是我需要用,如果暂时不需要的话可以省略后续操作

npm install vue -g
npm install vue-cli -g

然后进行

npm install
npm run dev

在运行时候出现了are-we-there-yet的错误
解决方法如下:

1) Go to the global node_modules directory (what would npm root -g print if you could run it):
 
$ cd /usr/local/lib/node_modules
2) Remove the broken npm directory or move it somewhere else (note that you might need to elevate permissions for this and the following steps):
 
$ mv npm /tmp
3) Download and unpack fresh npm from the registry (substitute version you want to install, e.g. 3.10.8):
 
$ curl -L registry.npmjs.com/npm/-/npm-{VERSION}.tgz | tar xz --transform="s:^package:npm:"
You can automate some of that with this install script:
 
$ curl -L https://www.npmjs.com/install.sh | sh

至此,再运行

npm run dev

就可以使用了。

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐