Installing packages using Bower in your Windows machine

In the last post, I have detailed the steps needs for installing Bower in your Windows machine and in this one I will be showing how to use Bower to install packages in your projects. If you have missed my earlier one on installation, you can read it here.

If you want to use bower in your project, you need to initialize it first. You can do that using the bower init command to create bower.json file in the root folder and you can create one manually using any text editor.

When you execute init command, it will ask some questions and it's not mandatory to give answers for that. Once it's with collecting data it will ask for a confirmation to save the changes and creates the json file.

bower init

Output

So we have the environment setup for the project and let's add jQuery. Since I am not sure about the locations of the packages, I will search for it in the registry and will then install it. For searching the registry, we have got two options, one option is using the Bower website and other is from the command line.

Syntax for searching from CLI

bower search <query>

Usage

bower search jQuery

Output

Note: Before installing the package, make sure that Git client is installed in your machine and if it's not then refer my post here on how to install it in your Windows 10 box. Otherwise you will get an error like the one given below.

So I am going to select the first option for installing it and command for it is 

Syntax

bower install <package> --save

Usage

bower install jQuery --save 

Output

When you execute the command, bower will create a folder called bower_components in the project's root. Then will download the package from the feed and saves it to that folder. The --save command tells bower to add the reference in the bower.json file for future use.

If you want to install a specific version of jQuery, then there is an option to provide version number in the install command

Syntax

bower install <package>#version --save

Usage

bower install jQuery#2.1 --save

If the specified version number is not found, bower will some suggestion based on our selection as shown below.

Output

If you want to update a package, then execute the command below

Syntax

bower update <package name>

Usage

bower update jQuery --save

The above command will update only the jQuery package and if you want to update all the packages in the project you only need give the command like the one below.

bower update

Output

We can use the uninstall command to uninstall it from the project

Syntax

bower uninstall <package name> --save

Usage

bower uninstall jQuery --save

The --save switch will make sure that entry will be removed from the bower.json file along with the uninstallation.

Usage

      


No Comments

Add a Comment