Linux / Bash - add additional bin directory to system PATHs

7 points
Created by:

In this short article we would like to show how to add some program as command to environment PATH variable in Bash under Linux. Presented approach will help us to use as commands executable files located inside indicated path.

Quick solution (run command):

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

Where: /path/to/directory/with/bin should be replaced with path to directory that has executable files.

Note: above command executed in Bash adds path only for current session - it means after command line is closed the path is removed.

Detailed instruction

In this section we would like to show practical example how to add as Bash command.

Simple steps:

  1. open Bash,
  2. create some script that has path ~/bin/ and put inside some operations e.g.
    echo "Test!!!"
  3. add executable permissions for, (e.g. chmod a+x ~/bin/
  4. run following command:
    export PATH=~/bin:$PATH
  5. go to any place e.g. /home
  6. run following command:



    Note: we can see, we don't need to use full path to run ~/bin/ - Bash finds executable file automatically.

Console preview:

john@ubuntu:/mnt/john/$ cd ~/bin^C           
john@ubuntu:/mnt/john/$ nano ~/bin/
john@ubuntu:/mnt/john/$ chmod a+x ~/bin/                
john@ubuntu:/mnt/john/$ export PATH=~/bin:$PATH
john@ubuntu:/mnt/john/$ cd /home


Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - friendly IT community for everyone.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé