centos7 安装vue,安装node.js

该篇博客详细记录了在CentOS7上手动下载并安装Node.js v11.10.0的过程,通过修改profile文件设置环境变量。同时,它还涉及到了如何更换npm源为淘宝源,并安装cnpm。接着,博主安装了vue-cli并展示了如何修改端口。最后,博客提到了在项目中遇到的console.log警告,并展示了项目的打包过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[root@ip-172-31-32-101 bin]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)

别的博客说yum安装的版本会和开发版不统一,下载node.js

 https://nodejs.org/dist/    可以看到列表选择版本链接
wget https://nodejs.org/dist/v11.10.0/node-v11.10.0-linux-x64.tar.gz
tar -zxvf node-v11.10.0-linux-x64.tar.gz
mv node-v11.10.0-linux-x64 node-v11

建立软连接或者修改profile文件(下面两者选其一)
(1)修改profile文件

vi /etc/profile
#在末尾添加
#set for nodejs
export NODE_HOME=/opt/download/node-v11 # node所在路径,你自己解压在哪写哪
export PATH=$NODE_HOME/bin:$PATH

保存退出,然后让命令生效输入

source /etc/profile

(2)建立链接的方法

ln -s /opt/download/node-v11/bin/node /usr/bin/node
ln -s /opt/download/node-v11/bin/npm /usr/bin/npm
node -v
npm -v

换下npm的源:npm config set registry https://registry.npm.taobao.org

[root@ip-172-31-32-101 bin]# npm config set registry https://registry.npm.taobao.org

验证源是否更换: npm config get registry

[root@ip-172-31-32-101 bin]# npm config get registry

https://registry.npm.taobao.org/
安装cnpm :
建立软链,否则在使用cnpm时会报No command ‘cnpm’ found的错误。(如果前面是添加的环境变量文件就不用执行这个软链接)

    ln -s /opt/download/node-v11/bin/cnpm /usr/local/bin/cnpm
# npm install -g cnpm --registry=https://registry.npm.taobao.org
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 har-validator@5.1.5: this library is no longer supported
/opt/download/node-v11/bin/cnpm -> /opt/download/node-v11/lib/node_modules/cnpm/bin/cnpm
+ cnpm@7.0.0
added 713 packages from 970 contributors in 15.956s

验证是否安装成功

# cnpm -v
cnpm@7.0.0 (/opt/download/node-v11/lib/node_modules/cnpm/lib/parse_argv.js)
npm@6.14.15 (/opt/download/node-v11/lib/node_modules/cnpm/node_modules/npm/lib/npm.js)
node@11.10.0 (/opt/download/node-v11/bin/node)
npminstall@5.0.2 (/opt/download/node-v11/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js)
prefix=/opt/download/node-v11 
linux x64 3.10.0-1127.19.1.el7.x86_64 
registry=https://registry.nlark.com

安装vue-cli

# cnpm install -g vue-cli
Downloading vue-cli to /opt/download/node-v11/lib/node_modules/vue-cli_tmp
Copying /opt/download/node-v11/lib/node_modules/vue-cli_tmp/_vue-cli@2.9.6@vue-cli to /opt/download/node-v11/lib/node_modules/vue-cli
Installing vue-cli's dependencies to /opt/download/node-v11/lib/node_modules/vue-cli/node_modules
[1/20] commander@^2.9.0 installed at node_modules/_commander@2.20.3@commander
[2/20] semver@^5.1.0 installed at node_modules/_semver@5.7.1@semver
[3/20] uid@0.0.2 installed at node_modules/_uid@0.0.2@uid
[4/20] coffee-script@1.12.7 installed at node_modules/_coffee-script@1.12.7@coffee-script
[5/20] consolidate@^0.14.0 installed at node_modules/_consolidate@0.14.5@consolidate
[6/20] validate-npm-package-name@^3.0.0 installed at node_modules/_validate-npm-package-name@3.0.0@validate-npm-package-name
[7/20] user-home@^2.0.0 installed at node_modules/_user-home@2.0.0@user-home
[8/20] tildify@^1.2.0 installed at node_modules/_tildify@1.2.0@tildify
[9/20] minimatch@^3.0.0 installed at node_modules/_minimatch@3.0.4@minimatch
[10/20] read-metadata@^1.0.0 installed at node_modules/_read-metadata@1.0.0@read-metadata
[11/20] handlebars@^4.0.5 installed at node_modules/_handlebars@4.7.7@handlebars
[12/20] multimatch@^2.1.0 installed at node_modules/_multimatch@2.1.0@multimatch
[13/20] chalk@^2.1.0 installed at node_modules/_chalk@2.4.2@chalk
[14/20] rimraf@^2.5.0 installed at node_modules/_rimraf@2.7.1@rimraf
[15/20] async@^2.4.0 installed at node_modules/_async@2.6.3@async
[16/20] ora@^1.3.0 installed at node_modules/_ora@1.4.0@ora
[17/20] request@^2.67.0 installed at node_modules/_request@2.88.2@request
[18/20] metalsmith@^2.1.0 installed at node_modules/_metalsmith@2.3.0@metalsmith
[19/20] download-git-repo@^1.0.1 installed at node_modules/_download-git-repo@1.1.0@download-git-repo
[20/20] inquirer@^6.0.0 installed at node_modules/_inquirer@6.5.2@inquirer
deprecate request@^2.67.0 request has been deprecated, see https://github.com/request/request/issues/3142
deprecate coffee-script@1.12.7 CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
deprecate request@2.88.2 › har-validator@~5.1.3 this library is no longer supported
deprecate request@2.88.2 › uuid@^3.3.2 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.
Recently updated (since 2021-09-03): 1 packages (detail see file /opt/download/node-v11/lib/node_modules/vue-cli/node_modules/.recently_updates.txt)
  2021-09-07
    → handlebars@4.7.7 › uglify-js@^3.1.4(3.14.2) (22:54:44)
All packages installed (234 packages installed from npm registry, used 5s(network 5s), speed 1.11MB/s, json 220(491.4KB), tarball 4.58MB)
[vue-cli@2.9.6] link /opt/download/node-v11/bin/vue@ -> /opt/download/node-v11/lib/node_modules/vue-cli/bin/vue
[vue-cli@2.9.6] link /opt/download/node-v11/bin/vue-init@ -> /opt/download/node-v11/lib/node_modules/vue-cli/bin/vue-init
[vue-cli@2.9.6] link /opt/download/node-v11/bin/vue-list@ -> /opt/download/node-v11/lib/node_modules/vue-cli/bin/vue-list

建立软连接:(如果前面是添加的环境变量文件就不用执行这个软链接)

ln -s /home/node/node-v11/bin/vue /usr/local/bin/vue

验证

# vue -V
[root@ip-172-31-32-101 bin]# vue -V
2.9.6

vue3.x运行后, 默认在8080端口运行,想换一个端口的话,不能用vue2.x中修改config/index.js的方法 。

App running at:

  • Local: http://localhost:9001/
  • Network: http://192.168.43.173:9001/

解决方法:
打开package.json

“scripts”: {
“build”: “vue-cli-service build”,
“serve”: “vue-cli-service serve --port 9001”
},

再次npm run serve,就切换到了9001端口。

####################################################
npm 更新 npm i -g npm
下载依赖的时候报错,于是
npm install --no-optional --verbose 执行了这个一命令(这个没执行,只是记录一下)。
chmod 755 /opt/download/zhuanma/node_modules/.bin/vue-cli-service
####################################################

[root@ip-172-31-32-101 zhuanma]# npm run build
(node:16274) ExperimentalWarning: The fs.promises API is experimental

> zmxt@0.1.0 build
> vue-cli-service build


?  Building for production...


 WARNING  Compiled with 11 warnings                                                                                                                                                                                                1:37:20 PM

Module Warning (from ./node_modules/eslint-loader/index.js):

/opt/download/zhuanma/src/views/Home.vue
  101:5  warning  Unexpected console statement  no-console
  104:5  warning  Unexpected console statement  no-console

? 2 problems (0 errors, 2 warnings)


Module Warning (from ./node_modules/eslint-loader/index.js):

/opt/download/zhuanma/src/views/login/index.vue
   33:4  warning  Unexpected console statement  no-console
  100:6  warning  Unexpected console statement  no-console

? 2 problems (0 errors, 2 warnings)


Module Warning (from ./node_modules/eslint-loader/index.js):

/opt/download/zhuanma/src/views/renwu/edit.vue
  143:6  warning  Unexpected console statement  no-console
  187:6  warning  Unexpected console statement  no-console
  207:6  warning  Unexpected console statement  no-console
  243:6  warning  Unexpected console statement  no-console

? 4 problems (0 errors, 4 warnings)


Module Warning (from ./node_modules/eslint-loader/index.js):

/opt/download/zhuanma/src/views/renwu/index.vue
  188:5  warning  Unexpected console statement  no-console

? 1 problem (0 errors, 1 warning)


Module Warning (from ./node_modules/eslint-loader/index.js):

/opt/download/zhuanma/src/views/user/index.vue
   91:7  warning  Unexpected console statement  no-console
  106:6  warning  Unexpected console statement  no-console

? 2 problems (0 errors, 2 warnings)


Module Warning (from ./node_modules/eslint-loader/index.js):

/opt/download/zhuanma/src/views/video/index.vue
  154:5  warning  Unexpected console statement  no-console
  202:5  warning  Unexpected console statement  no-console
  203:5  warning  Unexpected console statement  no-console
  266:7  warning  Unexpected console statement  no-console
  341:5  warning  Unexpected console statement  no-console
  367:5  warning  Unexpected console statement  no-console
  368:5  warning  Unexpected console statement  no-console
  385:7  warning  Unexpected console statement  no-console
  408:5  warning  Unexpected console statement  no-console
  435:7  warning  Unexpected console statement  no-console
  440:5  warning  Unexpected console statement  no-console
  540:6  warning  Unexpected console statement  no-console
  559:6  warning  Unexpected console statement  no-console
  648:6  warning  Unexpected console statement  no-console
  679:5  warning  Unexpected console statement  no-console

? 15 problems (0 errors, 15 warnings)


Module Warning (from ./node_modules/eslint-loader/index.js):

/opt/download/zhuanma/src/views/zhuanm/edit.vue
  157:5  warning  Unexpected console statement  no-console
  186:6  warning  Unexpected console statement  no-console
  191:6  warning  Unexpected console statement  no-console
  277:6  warning  Unexpected console statement  no-console

? 4 problems (0 errors, 4 warnings)


Module Warning (from ./node_modules/eslint-loader/index.js):

/opt/download/zhuanma/src/views/zhuanm/index.vue
   81:5  warning  Unexpected console statement  no-console
   89:6  warning  Unexpected console statement  no-console
  122:5  warning  Unexpected console statement  no-console
  189:5  warning  Unexpected console statement  no-console

? 4 problems (0 errors, 4 warnings)


You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
 warning  in ./src/main.js

Module Warning (from ./node_modules/thread-loader/dist/cjs.js):

/opt/download/zhuanma/src/main.js
  14:2  warning  Unexpected console statement  no-console

? 1 problem (0 errors, 1 warning)


 @ multi ./src/main.js

 warning  

asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.
Assets: 
  img/dlbj.bdd36438.png (3.01 MiB)
  css/chunk-vendors.d2d1c1da.css (261 KiB)
  js/chunk-vendors.cf06b048.js (806 KiB)

 warning  

entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
Entrypoints:
  app (1.05 MiB)
      css/chunk-vendors.d2d1c1da.css
      js/chunk-vendors.cf06b048.js
      css/app.305a1915.css
      js/app.e85a8435.js


  File                                    Size                                                                                            Gzipped

  dist/js/chunk-vendors.cf06b048.js       806.22 KiB                                                                                      235.17 KiB
  dist/js/chunk-58b35182.cde7c11a.js      31.68 KiB                                                                                       10.95 KiB
  dist/js/chunk-5a7100b0.e992d4bb.js      30.12 KiB                                                                                       9.42 KiB
  dist/js/chunk-4d727779.241b26a5.js      11.91 KiB                                                                                       7.33 KiB
  dist/js/chunk-3e58a1ac.f9828a49.js      11.09 KiB                                                                                       3.59 KiB
  dist/js/chunk-0978a9ac.126c0013.js      10.82 KiB                                                                                       3.75 KiB
  dist/js/app.e85a8435.js                 5.86 KiB                                                                                        2.49 KiB
  dist/js/chunk-71b45003.aeba9ec6.js      5.37 KiB                                                                                        2.27 KiB
  dist/js/chunk-78fe28c0.f38e721d.js      5.05 KiB                                                                                        2.19 KiB
  dist/js/chunk-25141336.71e1f01a.js      2.57 KiB                                                                                        1.23 KiB
  dist/js/chunk-70b5ae6f.a085234f.js      2.51 KiB                                                                                        1.08 KiB
  dist/css/chunk-vendors.d2d1c1da.css     260.82 KiB                                                                                      38.23 KiB
  dist/css/chunk-58b35182.6fdd1b2e.css    3.44 KiB                                                                                        1.03 KiB
  dist/css/chunk-71b45003.f5d8bd78.css    2.99 KiB                                                                                        0.88 KiB
  dist/css/chunk-4d727779.8ca62c70.css    2.20 KiB                                                                                        0.80 KiB
  dist/css/chunk-3e58a1ac.dc2d52af.css    2.19 KiB                                                                                        0.73 KiB
  dist/css/chunk-0978a9ac.6b18aeac.css    1.85 KiB                                                                                        0.65 KiB
  dist/css/chunk-70b5ae6f.ad39f1f0.css    1.33 KiB                                                                                        0.53 KiB
  dist/css/chunk-25141336.be070de1.css    0.90 KiB                                                                                        0.43 KiB
  dist/css/chunk-78fe28c0.b9bdeae5.css    0.30 KiB                                                                                        0.22 KiB
  dist/css/app.305a1915.css               0.08 KiB                                                                                        0.09 KiB

  Images and other types of assets omitted.

 DONE  Build complete. The dist directory is ready to be deployed.
 INFO  Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html

初始化一个名为renren-fast-vue的项目

vue init webpack renren-fast-vue

npm i -g npm
npm install -g @vue/cli
cnpm install -g @vue/cli
vue
vue -V
npm --registry https://registry.npm.taobao.org info underscore
npm install
cnpm install
npm run build

查看配置:

[root@ip-172-31-32-101 qdym]# npm config list
(node:29163) ExperimentalWarning: The fs.promises API is experimental
; "user" config from /root/.npmrc

registry = "https://registry.npm.taobao.org/" 

; node bin location = /opt/download/node-v11/bin/node
; cwd = /opt/zhuanma/qdym
; HOME = /root
; Run `npm config ls -l` to show all defaults.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值