1

I have a question regarding the PATH variable and ways to configure it.

The question stems from the fact that the installation of a software package am dealing with comes with a bash script which is responsible to configure the PATH.

That script fails to do so,and this is where I take over, and try to do that manually.

I have tried some methods like:

PATH=$PATH:~/opt/bin           # or
PATH=~/opt/bin:$PATH           # or
export PATH=~/opt/bin:$PATH    # or
export PATH=$PATH:~/opt/bin    # or
export PATH=$PATH:/opt/bin     # or
PATH=$PATH:/opt/bin            # and
export PATH 

then I run:

echo $PATH

to see the effect, but nothing appears to be changed.

I do all that in a Linux mint partition.

My question is if is there anything else that I need to do before trying to change the PATH in order for any change to take effect?Or is simply the way am approaching the problem ineffective?

Is there any other way to add variables in the PATH (any kind of software or similar?)

George

16
  • Which terminal or console are you using to execute the commands?
    – user79743
    Mar 26, 2016 at 20:45
  • 1
    "Nothing appears to be changed" - in what way? What do you expect the effect to be? How are you testing it? Also, are you sure the correct additional path is /opt/bin rather than /opt/<name of software>/bin? Mar 26, 2016 at 21:02
  • @BinaryZebra am using the normal terminal.
    – Rizias
    Mar 26, 2016 at 22:42
  • @RealSkeptic When I say "Nothing appears to be changed" I mean that there is no addition to the PATH after hitting echo $PATH (this is how I test it).The opt/bin is used only for illustration purposes (sorry for the confusion)
    – Rizias
    Mar 26, 2016 at 22:43
  • What shell are you using? a bourne-like shell (sh, bash, ash, dash, ksh, zsh etc) or a c shell (such as csh or, tcsh)? The commands you used should work with a bourne shell (unless PATH has been set readonly, but an error message will tell you that if that's the case), but for csh you need to do something like set PATH="$PATH:/opt/bin". more importantly, if you're using csh, you need to stop that and start using bash or ksh or zsh instead.
    – cas
    Mar 26, 2016 at 23:42

2 Answers 2

1

The value of PATH is set initially inside the file /etc/profile.

It is set both for a "default user" and "root" (do not edit it).
You can read it by executing this command in a terminal:

cat /etc/profile

However, you want to change the default PATH only for your user (so other users may have a different PATH, and specially the user root).

In Mint (and that may be different for different versions of Mint) with a Gnome desktop (create or edit ~/.pam_environment as follows). Assuming you have a text editor called gedit:

$ gedit ~/.pam_environment

And add (or change) this line:

PATH DEFAULT=${PATH}:/opt/bin

write the file, log out, log-in again and the new value of PATH should be in effect.

This answer helped me to write my answer.

0
0

You cannot change the PATH (or any other environment variable) for a shell process by running a script.

If the script modifies (and exports) PATH, then the modifications will only affect the environment within the script (and any subprocess) but not the parent process.

If you want to modify the PATH within your running shell session, you need to modify it directly in this session, eg by sourceing the script rather than running it.

$ cat mypath.sh
export PATH=/opt/foo/bin:$PATH
$ echo $PATH
/usr/bin
$ ./mypath.sh
$ echo $PATH
/usr/bin
$ . ./mypath.sh
$ echo $PATH
/opt/foo/bin:/usr/bin
1
  • Thank you very much for answering,I wanted to say source the script rather thank running.Sorry about that...
    – Rizias
    Mar 27, 2016 at 22:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .