61

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 
6
  • 1
    You probably just need to enclose right-hand side of the expression in double quotes, e.g. PATH="...". Commented Jan 15, 2014 at 7:47
  • 1
    Try PATH="$JAVA_HOME/bin:$PATH:/usr/java/jdk1.7.0_45/bin/:$AWS_AUTO_SCALING_HOME/bin". It's just a guess. Commented Jan 15, 2014 at 7:50
  • I am still getting the error : -bash: as-cmd: command not found Commented Jan 15, 2014 at 7:53
  • 1
    Then it's probably something wrong with contents of the $PATH, you seem to setup correctly. Commented Jan 15, 2014 at 7:56
  • please if you could help me out. I am struck since last 4 hours Commented Jan 15, 2014 at 8:00

6 Answers 6

115

$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
Sign up to request clarification or add additional context in comments.

7 Comments

please see i have to update bash_profile directly without exporting the path.
So what's the problem with your example? What exactly does not work?
i have installed the aws-autoscaling tool but its not working. i have followed the link docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/…
Your usage of the $PATH variable seems correct. Can you share the specific error?
Tried this and couldn't find any executable, not even vi or cd. Had to change it to export PATH="$PATH~/something"
|
13

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.

Comments

6

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

Comments

4

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.

3 Comments

This is my favorite way, it's the cleanest solution.
why the \ after :
thanks for pointing it out, it has been removed.
4
  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:\$VARIABLE_NAME2
    • export PATH
  3. Logout from user and Relogin

Comments

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

1 Comment

Welcome to Stack Overflow! While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.