linux 下bower安装和使用

本文详细介绍了在Linux系统中如何安装npm、Bower,并通过Bower安装jQuery插件。首先,讲解了安装npm的必要性和方法,接着阐述了Bower的安装过程,特别提到在遇到权限问题时如何添加--allow-root参数。此外,还提到了如果缺少git,需要先安装git。安装Bower后,会自动创建bower_components目录来存放下载的插件。最后,介绍了如何更新、卸载插件以及如何修改默认的存储目录,通过创建.bowerrc文件进行配置。

一、安装npm

安装node主要是为了使用npm命令,也可以单独安装npm。
安装node可查看如下文章https://blog.csdn.net/huangbaokang/article/details/81092247

二、安装bower

 npm install -g bower

三、安装jquery插件

使用bower install jquery命令即可,如果报了如下错,根据提示加上–allow-root参数即可。

[root@localhost hbk]# bower install jquery
bower ESUDO         Cannot be run with sudo

Additional error details:
Since bower is a user command, there is no need to execute it with superuser permissions.
If you're having permission errors when using bower without sudo, please spend a few minutes learning more about how your system should work and make any necessary repairs.

http://www.joyent.com/blog/installing-node-and-npm
https://gist.github.com/isaacs/579814

You can however run a command with sudo using "--allow-root" option

如果没有git,可以使用yum install git

安装完之后,在执行命令目录下新建了一个bower_components目录,里面下载用到的插件。

更新插件

bower update jquery --allow-root

卸载插件

bower uninstall jquery

修改默认的文件夹bower_components,建立一个.bowerrc文件

配置成如下:

{  
  "directory" : "js/huangbaokang",  
  "json"      : "",  
  "endpoint"  : "",  
  "searchpath"  : "",  
  "shorthand_resolver" : ""  
}  

再次执行,可以看到存储到了我们自定义的目录了。

[root@localhost hbk]# bower install jquery --allow-root
bower cached        https://github.com/jquery/jquery-dist.git#3.3.1
bower validate      3.3.1 against https://github.com/jquery/jquery-dist.git#*
bower install       jquery#3.3.1

jquery#3.3.1 js/huangbaokang/jquery

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄宝康

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值