Linux安装Nodejs

作者: 右耳菌 | 来源:发表于2022-11-15 16:13 被阅读0次

首先要确定自己要安装的版本,这里以16.12.0版本为例

tar -zxvf node-v16.12.0-linux-x64.tar.gz -C /usr/local/
  • 改一下文件夹的名字,我只是觉得太长了,如果不想改可以忽略这一步
mv /usr/local/node-v16.12.0-linux-x64 /usr/local/node-v16.12.0
  • 创建软连接,因为我们改过文件夹名称了,所以这里是node-v16.12.0,如果没有改或者改成了其他,记得相应改动自行匹配一下。
ln -s /usr/local/node-v16.12.0/bin/node /usr/local/bin/
ln -s /usr/local/node-v16.12.0/bin/npm /usr/local/bin/
ln -s /usr/local/node-v16.12.0/bin/npx /usr/local/bin/
  • 最后测试一下
[root@lazyfennec local]# node -v
v16.12.0
[root@lazyfennec local]# npm -v
8.1.0
[root@lazyfennec local]# npm -v
8.1.0
[root@lazyfennec local]# 

添加一个cnpm指向国内的淘宝镜像

  • 执行以下命令
npm install -g cnpm --registry=https://registry.npm.taobao.org

此时还是无法使用cnpm 的,但是我们会发现在 /usr/local/node-v16.12.0/bin/下已经存在了一个cnpm,那么同上,我们创建一个软连接就好了。

  • 创建软连接
ln -s /usr/local/node-v16.12.0/bin/cnpm /usr/local/bin/

这个时候我们就可以测试一下cnpm了

[root@lazyfennec bin]# cnpm -h

  Usage: cnpm [options]

  Options:

    -h, --help                       output usage information
    -v, --version                    show full versions
    -r, --registry [registry]        registry url, default is https://registry.npmmirror.com
    -w, --registryweb [registryweb]  web url, default is https://npmmirror.com
    --disturl [disturl]              dist url for node-gyp, default is https://npmmirror.com/mirrors/node
    -c, --cache [cache]              cache folder, default is /root/.cnpm
    -u, --userconfig [userconfig]    userconfig file, default is /root/.cnpmrc
    -y, --yes                        yes all confirm
    --ignore-custom-config           ignore custom .cnpmrc
    --proxy [proxy]                  set a http proxy, no default

Usage: cnpm [option] <command>
Help: http://cnpmjs.org/help/cnpm

  Extend command
    web                            open cnpm web (ex.: cnpm web)
    check [ingoreupdate]           check project dependencies, add ignoreupdate will not check modules' latest version(ex.: cnpm check, cnpm check -i)
    doc [moduleName]               open document page (ex.: cnpm doc egg)
    sync [moduleName]              sync module from source npm (ex.: cnpm sync egg)
    user [username]                open user profile page (ex.: cnpm user fengmk2)

  npm command use --registry=https://registry.npmmirror.com
    where <command> is one of:
    add-user, adduser, apihelp, author, bin, bugs, c, cache,
    completion, config, ddp, dedupe, deprecate, docs, edit,
    explore, faq, find, find-dupes, get, help, help-search,
    home, i, info, init, install, isntall, la, link, list, ll,
    ln, login, ls, outdated, owner, pack, prefix, prune,
    publish, r, rb, rebuild, remove, restart, rm, root,
    run-script, s, se, search, set, show, shrinkwrap, star,
    start, stop, submodule, tag, test, tst, un, uninstall,
    unlink, unpublish, unstar, up, update, v, version, view,
    whoami
      npm <cmd> -h     quick help on <cmd>
      npm -l           display full usage info
      npm faq          commonly asked questions
      npm help <term>  search for help on <term>
      npm help npm     involved overview

      Specify configs in the ini-formatted file:
          /root/.cnpmrc
      or on the command line via: npm <command> --key value
      Config info can be viewed via: npm help config

至此,安装完成,可以使用了,鼓个掌,clap clap clap~~~


如果觉得有收获,欢迎点赞和评论,更多知识,请点击关注查看我的主页信息哦~

相关文章

网友评论

    本文标题:Linux安装Nodejs

    本文链接:https://www.haomeiwen.com/subject/eufexdtx.html