Sehran Hasanli
Sehran Hasanli

Reputation: 41

How to add a full path to the PATH variable using Bash?

How do you add a full path to the PATH variable using Bash? I've tried for example somthing like

export PATH=/myPath:$PATH

but it doesn't work.

Upvotes: 0

Views: 210

Answers (2)

Robin Green
Robin Green

Reputation: 33103

The export command only takes effect in the current shell, for all programs started subsequently to that export command.

To make it take effect for other shells, and after you logout, you'll need to add the command to your ~/.bashrc file and restart the other terminal windows/tabs.

To make it take effect for GUI applications when they are not started directly or indirectly from a terminal window, an additional step may be required.

To make it take effect for applications running as another user (e.g. root), a different additional step may be required.

Upvotes: 1

akhikhl
akhikhl

Reputation: 2578

The code you mentioned above works perfectly well: PATH variable gets changed - for current bash session and all processes started from it.

The source of the problem is probably the following:

Your program gets a copy of environment variables on it's start. If environment variable (PATH or anything else) is changed after the program start, the program will not "see" the change. You'll need to restart a program.

Upvotes: 0

Related Questions