How to Install Bower on Ubuntu

Bower is the package manager that is used to manage the websites on the internet. When the website is made, users are supposed to track the libraries, frameworks, and other utilities related to the website. 

It also provides the users ease by ensuring the latest packages of Java, HTML, and CSS are being installed. It makes a JSON file and keeps track of the finding, downloading, installing, and upgrading of the packages. 

Bower can be installed on Ubuntu by running different commands on the terminal. This post explains all the commands with their execution for installing the Bower on Ubuntu. 

Prerequisites

The following packages should be installed on Ubuntu for the smooth operation of Bower:

  • Node.js and NPM packages should be installed on Ubuntu with the instructions explained in the blog
  • A package of Git should be installed on Ubuntu using the commands explained in the blog

How to Install Bower on Ubuntu?

To install the Bower on Ubuntu, execute the commands mentioned in the below steps. 

Step 1: Launch the Terminal of Ubuntu

First, launch the terminal of Ubuntu with the shortcut key CTRL+ALT+T to execute the commands:

Step 2: Update the Packages

Now, ensure the installation of the latest packages by updating all the packages of Ubuntu using the command:

$ sudo apt update

Step 3: Verify the Installation of NPM

To verify the NPM package has been installed, execute the command:

$ npm --version

Step 4: Verify the Installation of Git

Also, display the version of the installed Git package on Ubuntu:

$ git --version

Step 5: Install Bower on Ubuntu

Bower can be installed on Ubuntu with the “install” option of the apt package manager:

$ sudo npm install -g bower

Step 6: Verify the Installation of Bower

Verify the installation of the Bower on Ubuntu by displaying its version:

$ bower --version

What are the Basic Commands of the Bower on Ubuntu?

To use the Bower on Ubuntu, some of its basic commands are explained in this section.

Create a JSON File

To create the JSON file, initialize the bower with the command:

$ bower init

Install Packages

To install the packages with the Bower, use the command:

$ bower install [Package Name]

Search the Package

To search for the specific package with the “Bower”, run the command:

$ bower search [Package Name]

Install a Package from GitHub

To install the specific package from the GitHub repository, use the command:

$ bower install git://github.com/user/[package name.git]

Install a Package Using the URL

Another method of installing the package with the Bower is by using the URL address of the package script:

$ bower install http://example.com/script.js

These are some basic commands of the Bower.

How to Set Up a Project in Bower?

After installing it, adhere to the directions for creating a project in Bower. In the steps below, a sample project is being created for the user’s understanding. 

Step 1: Create and Navigate the Directory

First, use the “mkdir” command to create a new directory and then access it with the “cd” command. For example, we will create the directory with the name “itslinuxfoss_project”:

$ mkdir itslinuxfoss_project && cd itslinuxfoss_project

Step 2: Initialize the New Project

Now initialize the new Bower project with the command:

$ bower init

Step 3: Install the Dependencies

After installing the new project, install the dependencies of the project. For instance, install the jQuery library with the command:

$ bower install jquery --save

The “–save” option used in the above command will save the project in the JSON file as well. 

Congratulations the project has been set up successfully. Now this project can be used to manage the web development’s front-end components. 

Conclusion

To install the Bower on Ubuntu, ensure the NPM package has been installed and then use the npm as “npm install -g bower” for installing Bower on Ubuntu. After the installation of Bower, set up a project and start managing the web development. In this post, the installation of Bower with its basic commands has been explained.