How to install http-server on Ubuntu system

Hello,

In this post I will show you how you can install http-server on your ubuntu system using node js environment via npm.

http-server allows you to create your own local server on your computer system.

To make http server run on your system, you must first install node js.

First of all, open terminal and make sure your system is connected to the internet. Now execute the folowing command:

sudo apt-get update

You will be prompted to enter the sudo password i.e. the admin password. Enter the password and your system will get different updates, this will take a few minutes.

Now execute the following command to install node js:

sudo apt-get install nodejs

Now node js environment will be installed on your system. To check whether node js is installed on your system try running:

node -v

This command will show you the version of node js environment installed on your system.

Now we need to install npm so that various package requirements to run http server are met. To install npm run the following command:

sudo apt-get install npm

To check whether npm is installed on your system try running the following command which will show the version of npm installed:

npm -vv

Now you can install http server via npm on your system by running the following command:

sudo npm install http-server -g

This will install http-server globally so that it may be run from the command line/ terminal.

After installing, lets check if http-server installed on your system is working or not. Now execute the following commands and Create a directory on desktop by running:

cd Desktop
mkdir http  (alternatively you can also use the gui to create directory)

Now go to that directory using

cd http

Create some files (txt or html) in this directory.

Now execute the following to run http-server, you will see you local host ip as well as another ip(when connected to internet) along with the port i.e. 8080 (here my 8080 port is being used by another application so I am getting port 8081).




Now open Google Chrome and type any of the url in the url bar and hit enter. (Alternatively you can also right click on the ip and click on 'open link').
Now you will be able to see your files from the directory http(if created).





If everything works well on your system as stated above, http-server is installed on your system. Now you can host your file on your local server.

Comments

Popular Posts