linux 下bower安装和使用

一、安装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

你可能感兴趣的:(linux)