user3086014
user3086014

Reputation: 4511

How to add multiple path in $PATH variable linux?

I want to add multiple path in $path variable like java path and php path . how to do that in linux?

I am doing something in bash_profile like :

PATH=$JAVA_HOME/bin:$PATH:/usr/java/jdk1.7.0_45/bin/:$AWS_AUTO_SCALING_HOME/bin 

Upvotes: 61

Views: 143336

Answers (6)

Kingston Fortune
Kingston Fortune

Reputation: 957

If you're on a Mac, the best way in my opinion would be following Chamindu's answer with a slight tweak. using nano or vim whichever you prefer, but I'll use nano as it's easier for most people.

  1. Open Terminal and Type nano ~/.bash_profile to open bash profile.
  2. At the top, type or copy and paste the following:
    • FLUTTER="/Users/MyUsername/development/flutter/bin"
    • VSCODE="/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
    • PATH=$PATH:$FLUTTER:$VSCODE
    • export PATH
  3. If you're using nano as I suggested, do a control + x on your keyboard to exit.
  4. press Y to save your changes.
  5. In the terminal type source ~/.bash_profile to refresh your bash profile/environment variables.

Now you can navigate to any directory and call the files in your path.

Note:

  • Swap out FLUTTER and VSCODE for your variable names of choice.
  • You would only need to use sudo if you're not using the admin account.

Upvotes: 4

Sergio Melas
Sergio Melas

Reputation: 1

sudo CPATH=/usr/include/linux/:/usr/src/linux-headers-5.17.0-1-common/include/linux/ vmware-modconfig --console --install-all

Upvotes: 0

Chamindu Weerasinghe
Chamindu Weerasinghe

Reputation: 306

  1. Open Terminal and Type sudo gedit /etc/profile to open system path file
  2. Go to Bottom
    • VARIABLE_NAME1=/your/path/to/location1
    • VARIABLE_NAME2=/your/path/to/location2
    • PATH=$PATH:$VARIABLE_NAME1:\$VARIABL3_NAME2
    • export PATH
  3. Logout from user and Relogin

Upvotes: 3

user9652688
user9652688

Reputation:

One way to add multiple executables to the $PATH variable is:

export PATH=/path/to/executable1:\
/path/to/executable2:\
/path/to/executable3:\
/path/to/executable4

If a $PATH already exists in .bash_profile, and you want them to take precedence over executables (like java and php), you can do:

export PATH=$PATH:/path/to/executable1:\
/path/to/executable2:\
/path/to/executable3:\
/path/to/executable4

If the path to any executable contains whitespaces, add the part / ... executableX in quotes.

Once you're done making changes in your bash_profile, source the file in a terminal session so that changes are effective immediately:

source .bash_profile

Upvotes: 6

user3135746
user3135746

Reputation: 121

Set the $PATH environment variable to include the directory where you installed the bin directory with shell scripts and two consecutive export entries as in example.

Example:

export ANT_HOME=/path/to/ant/dir
export PATH=${PATH}:${ANT_HOME}/bin:${JAVA_HOME}/bin

To make them permanent entries update the bash_profile file.

Upvotes: 12

Mureinik
Mureinik

Reputation: 310983

$PATH can have several paths separated by a colon (:). E.g.:

export PATH=/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/myuser/bin

Upvotes: 115

Related Questions