博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Unix/Linux下安装NPM
阅读量:6912 次
发布时间:2019-06-27

本文共 2541 字,大约阅读时间需要 8 分钟。

hot3.png

就像NPM的官网()上介绍的那样,安装NPM仅仅是一行命令的事情:

curl http://npmjs.org/install.sh | sh

这里详解一下这句命令的意思,curl http://npmjs.org/install.sh是通过curl命令获取这个安装shell脚本,按后通过管道符| 将获取的脚本交由sh命令来执行。这里如果没有权限会安装不成功,需要加上sudo来确保权限:

curl http://npmjs.org/install.sh | sudo sh

安装成功后执行npm命令,会得到一下的提示:

Usage: npm where  is one of:adduser, apihelp, author, bin, bugs, c, cache, completion,config, deprecate, docs, edit, explore, faq, find, get,help, help-search, home, i, info, init, install, la, link,list, ll, ln, ls, outdated, owner, pack, prefix, prune,publish, r, rb, rebuild, remove, restart, rm, root,run-script, s, se, search, set, show, star, start, stop,submodule, tag, test, un, uninstall, unlink, unpublish,unstar, up, update, version, view, whoami

我们以underscore为例,来展示下通过npm安装第三方包的过程。

npm install underscore

返回:

underscore@1.2.2 ./node_modules/underscore

由于一些特殊的网络环境,直接通过npm install命令安装第三方库的时候,经常会出现卡死的状态。幸运的是国内CNode社区的同学利用空余时间搭建了一个镜像的NPM资源库,服务器架设在日本,可以绕过某些不必要的网络问题。你可以通过以下这条命令来安装第三方库:

npm --registry "" install underscore

如果你想将它设为默认的资源库,运行下面这条命令即可:

npm config set registry “”

设置之后每次安装时就可以不用带上—registry参数。值得一提的是还有另一个镜像可用,该镜像地址是,如需使用,替换上面两行命令的地址即可。

实际实践结果如下:

输入安装NPM的命令之后 有点慢。。哈

tar=/bin/tarversion:tar (GNU tar) 1.15.1fetching: http://registry.npmjs.org/npm/-/npm-1.0.106.tgz0.6.31.0.106cleanup prefix=/usr/localAll clean!/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js/usr/local/bin/npm-g -> /usr/local/lib/node_modules/npm/bin/npm-cli.js/usr/local/bin/npm_g -> /usr/local/lib/node_modules/npm/bin/npm-cli.jsnpm@1.0.106 /usr/local/lib/node_modules/npmIt worked
安装完成输入 NPM 测试 结果如下
[root@YX-MID node-v0.6.3]# npmUsage: npm where  is one of:    adduser, apihelp, author, bin, bugs, c, cache, completion,    config, deprecate, docs, edit, explore, faq, find, get,    help, help-search, home, i, info, init, install, la, link,    list, ll, ln, ls, outdated, owner, pack, prefix, prune,    publish, r, rb, rebuild, remove, restart, rm, root,    run-script, s, se, search, set, show, star, start, stop,    submodule, tag, test, un, uninstall, unlink, unpublish,    unstar, up, update, version, view, whoaminpm 
-h quick help on
npm -l display full usage infonpm faq commonly asked questionsnpm help
search for help on
npm help npm involved overviewSpecify configs in the ini-formatted file: /root/.npmrcor on the command line via: npm
--key valueConfig info can be viewed via: npm help config
 

转载于:https://my.oschina.net/zhangdapeng89/blog/52783

你可能感兴趣的文章
数据结构-----树状数组
查看>>
新手学习python(十六)封装redis
查看>>
vuex
查看>>
vux 全局使用 loading / toast / alert
查看>>
org.tinygroup.validate-验证框架
查看>>
session共享方法
查看>>
ASP.NET AJAX web chat application
查看>>
Codeforces Round #566 (Div. 2) B. Plus from Picture
查看>>
自己动手制作一个本地的yum仓库
查看>>
Ubuntu下用命令行快速打开各类型文件(转)
查看>>
Magento多语言设置——优化前台与后台实现方法
查看>>
leetcode121买股票
查看>>
SQL SERVER 2008中启用相应的功能
查看>>
Implementing a small Cron service in C# - CodeProject
查看>>
REST::Neo4p – PERL版本的”OGM”
查看>>
linux中service *** start与直接运行/usr/bin/***的区别
查看>>
剑指offer题目java实现
查看>>
Linux内核之于红黑树and AVL树
查看>>
LoaderManager使用详解(二)---了解LoaderManager
查看>>
EtherCAT对PHY有要求?
查看>>