How to Install Bootstrap with Bower

Bower is a popular package manager to help you quickly deploy components. In this article I’m going to show you how to install Bower and how to use it to install Bootstrap.

Pre-requisites: To install Bower you must first have Node.js and npm (another package manager) installed, your computer may have shipped with these pre-installed. To check if you have npm, open your command-line tool and type:

npm -v

If you do not get a version number, you may need to install npm which comes pre-packaged with Node.js

You can find Node.js along with instructions on how-to install it here: https://nodejs.org/en/

Windows Users Only: If you’re a Windows user make sure you have Git for Windows installed to work with the Windows Command Prompt with Checkout Windows-Style and commit Unix-style line endings. You can find more information on that here: https://git-for-windows.github.io

Installation:

Provided that you have both Node.js and npm installed, run the following command in your Command-line tool:

npm install -g bower

 

Usage:

Once Bower is installed it’s as easy as going to your project folder in Command-line and typing:

bower install bootstrap

This will install the files required for Boostrap in the newly created ‘bower_components’ folder.

In this folder you will have 2 new folders ‘bootstrap’ and ‘jquery’.

jQuery will be automatically downloaded by Bower as it’s required for running Bootstrap.

The next step is to include the files for both bootstrap and jQuery into your project file(s).

<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20type%3D%22text%2Fjavascript%22%20src%3D%22%2Fbower_components%2Fjquery%2Fdist%2Fjquery.min.js%22%3E%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" />
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20type%3D%22text%2Fjavascript%22%20src%3D%22%2Fbower_components%2Fbootstrap%2Fdist%2Fbootstrap.min.js%22%3E%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" />
<link rel="stylesheet" type="text/css" href="/bower_components/bootstrap/dist/ bootstrap.min.css">

That’s it, you should be good to go.

Updating

If you need to update a project and are unsure which bower packages you have installed that might need an update, you can type

bower list

in your project directory for a listing of packages you installed via Bower and which ones are due for an update.

in this case if we wanted to update our bootstrap install we would do:

bower update bootstrap

 

Making your Bower configurations portable

Once you have figured out your configurations and installed all of your desired Bower packages you can use:

bower init

Follow the steps provided in your Command-line.

This will initialize a bower.json file which will store your configurations.

Once you have your Bower.json file you can move it around to other locations or projects and you can get Bower to reinstall all of your packages and configurations by typing:

bower install

This will get Bower to create another ‘bower_components’ folder with the same packages and configurations specified in your bower.json file.

For further information on using or configuring Bower You can checkout the official website

About 

Software Engineer and adventure seeker with a knack for fun facts. Originally from the East Coast of Canada, moved to Vancouver to enjoy its mild climate and now staying for its scenic hikes.