Wednesday, 24 February 2021

$PATH what is it

 

PATH is an environmental variable in Linux and other Unix-like operating systems that tells the shell which directories to search for executable files (i.e., ready-to-run programs) in response to commands issued by a user. It increases both the convenience and the safety of such operating systems and is widely considered to be the single most important environmental variable.


http://www.linfo.org/path_env_var.html

For example, to add the directory /usr/sbin, the following would be used:

PATH="/usr/sbin:$PATH"

An alternative is to employ the export command, which is used to change aspects of the environment. Thus, the above absolute path could be added with the following two commands in sequence

PATH=$PATH:/usr/sbin
export PATH

or its single-line equivalent

export PATH=$PATH:/usr/sbin


:  is the separator means the next path

 https://stackoverflow.com/questions/35737627/what-does-the-colon-do-in-path



echo $PATH

will tell you what it is right now 

On a default Ubuntu desktop install $PATH is:

$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
https://askubuntu.com/questions/386629/what-are-the-default-path-values

It is set in .bash_profile

for example 

$PATH is the original path in the system

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
        PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
        PATH="$HOME/.local/bin:$PATH"
fi

export PATH="$PATH:/opt/mssql-tools/bin"
# GO
export GOROOT="/usr/local/go"
export GOPATH="$HOME/goworkspace/project1"
export PATH="$GOPATH/bin:$GOROOT/bin:$PATH"

if you type 

which bash
    /usr/bin/bash 

which php
    /usr/bin/php 

You will see bash (command line interpretor)  and php are installed in /usr/bin which is already included in default path


No comments:

Post a Comment