1. 程式人生 > >linux 下bower安裝和使用

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引數即可。

[[email protected] 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" : ""  
}  

再次執行,可以看到儲存到了我們自定義的目錄了。

[[email protected] 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