Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

A little time ago, I found out, that I can create custom commandterminals with expanding the PATH-variable. Unfortunately, it gets always resettet, when I close the terminal and opens it again.

Do you know how to fix this problem?

Because when I want to start a few scripts with terminalcommands, I don't want to expand the PATH-variable everytime before ...

share|improve this question
1  
Put it in your .bashrc? –  gniourf_gniourf Jun 24 '13 at 16:47
    
How to do that? I'm new on Linux ;) –  Jenne Jun 24 '13 at 16:48
1  
open your .bashrc file like so: gedit ~/.bashrc and put whatever you want in there (at the bottom of the file is better), e.g., PATH="~/my/cool/path/:$PATH" and export this variable: after the line you just entered, put export PATH then save the file, then close your terminal and reopen it and now your executables in ~/my/cool/path will be found. –  gniourf_gniourf Jun 24 '13 at 17:00
    
That worked very well, thanks a lot! –  Jenne Jun 24 '13 at 17:08
    
I wrote it up as a full answer for you... :) –  gniourf_gniourf Jun 24 '13 at 17:10

2 Answers 2

up vote 3 down vote accepted

I understand you have some executables in one of your home folders, e.g., in ~/bin and you want to be able to execute them without always typing the full path ~/bin/my_cool_executable.

You already observed that entering PATH=~/bin:$PATH in your terminal made things work... but only until you close the terminal. When you open a new one, your former PATH variable gets reset to its original value. By the way, I guess you know how to, at any time, check the value of the PATH variable: like so:

echo "$PATH"

How to make your change permanent so that your PATH will still be the same when you reopen a new terminal? It's very easy, you just need to edit your .bashrc file. Let's use the gedit editor: In a terminal, type this:

gedit ~/.bashrc

This opens up the gedit editor. Scroll to the end of the file and add this:

# Added by me on 2013/06/24
PATH=~/bin:$PATH
export PATH

and save the file and quit gedit. Then close your terminal and open a new one. Now your PATH variable should have ~/bin in front of it so that your commands in ~/bin will be accessible without typing their full path. And you know how to check that: echo "$PATH".

Enjoy!

Warning. It is considered bad practice and a security vulnerability to put . in your PATH variable.

share|improve this answer
    
So, that was really nice, but now I can't start the programs, when I am root. Do you know why and how to fix that? :) –  Jenne Jun 25 '13 at 19:38
    
In this case, one option is to put your programs in /usr/local/bin instead of fiddling with the PATH variable... or in /usr/local/sbin if they must only be accessed by root. –  gniourf_gniourf Jun 25 '13 at 19:56
    
Some have to be ran as root and some not. So it would be nice, if it wouldn't matter and they could be in a custom directory. So ist it able to do that? :) –  Jenne Jun 27 '13 at 15:16

Edit the PATH variable in the file /etc/environment.

That way the PATH changes are visible in the whole system and for every user.

share|improve this answer
2  
Don't do that!!! –  gniourf_gniourf Jun 24 '13 at 17:01
    
I changed it, but it doesn't work ... The command isn't found as well. –  Jenne Jun 24 '13 at 17:03
    
Why not? There is no other transparent way to change the environment globally? Of course you have to be careful. –  ortang Jun 24 '13 at 18:52
    
@ortang Because it's close to dangerous. In case you fuck up the consequences are a lot worse compared to editing it for a single user. You can still boot up in recovery mode when you made a mistake in ~/.bashrc or ~/.profile, but not if you do this here. It's just something to avoid editing if not needed and it's dangerous for users not exactly knowing what they're doing. –  gertvdijk Jul 14 '13 at 17:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.