Saturday, December 8, 2018

Path Variable in Ubuntu System


The paths defined in Ubuntu or any operating systems are searched to find out any commands given in command line terminal. If a program is installed from Debian(.deb) or windows installer(.exe), then the installer defined the path automatically. 

If we have not packaged installer, we get all files in a folder with a bin directory inside it with all executables. The bin folder contains executables should be available from the terminal, otherwise, we have to go into the executable location to execute the binary files.

There are two methods we can define path variable in Linux system (Actually, I tested it with Ubuntu 18.04 and 16.04, other Linux systems should also work.)

Method 1: User-specific path variable. 

Each user can define their own path variable. The path to define path variable is 
~/.bashrc

export PATH=/path/to/bin:$PATH

Then the following command makes it effective. 

$ source ~/.bashrc 

Or we can restart the terminal to take effect. 


Method 2: System path variable 

 This method is used to set the path variable globally, that means these path variables are defined systemwide. The path to define the path variable is 

/etc/environment

Just open it as a root user, add the path variable as follows:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/cassandra/bin:/path/to/bin"

Then run the following command to carry out effect:

$. /etc/environment

I hope this is helpful to you guys!

No comments:

Post a Comment