Recently I installed Android Studio. Now I want to add android-studio/bin/ persistently to PATH environmental variable as Session-wide environment variables and not as System-wide environment variables. To do that I tried to edit ~/.profile as described here. So I have these at the end of ~/.profile:

if [ -d "$HOME/bin" ] ; then

Then I re-login to initialize the variable. But when I run studio.sh in terminal, I get this:

studio.sh: command not found

Here are results of $PATH and echo $PATH:

$ $PATH 
bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
No such file or directory 
$ echo $PATH

Also I'm sure that ~/.bash_profile and ~/.bash_login do not exist. Now what cause the problem and how I can solve that?


I change end of ~/.profile to this, but it does not work:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then

It looks like you edited this code snippet:

if [ -d "$HOME/bin" ] ; then

which is included in ~/.profile by default.

The answer which lead you to do so is confusing IMNSHO.

I'd suggest that you change that code back to what it looked like before, and instead add a new line underneath it:

if [ -d "$HOME/bin" ] ; then


Then, next time you log in, PATH ought to be altered, whether $HOME/bin exists or not.

  • I tried that, but it does not work. I edited question, please see it again. – hasanghaforian Jan 30 '16 at 17:37
  • @hasanghaforian: Ok, I edited my answer too to clarify. – Gunnar Hjalmarsson Jan 30 '16 at 17:48
  • Thank you for your attention and help! But if I would to add another path, I have to add another line? – hasanghaforian Jan 30 '16 at 18:05
  • 1
    @hasanghaforian: Not necessarily. The point is that it shouldn't be between if and fi. As long as you keep it where it is now, you can say PATH="$PATH:/some/directory:/some/other/directory" – Gunnar Hjalmarsson Jan 30 '16 at 18:11
  • Once the path what is the command to execute the program globally? – Nick Pineda Sep 21 '16 at 16:07

OK, there's a couple issues here:

  1. Use echo $PATH instead of $PATH to check it!

    The reason for this is that bash replaces $PATH with the contents of that variable everywhere, so just running $PATH tries to execute the contents of the variable, which is nonsense to hte bash interpreter.

  2. You should add the content you added to ~/.profile to ~/.bashrc as well.

  3. Make sure that "$HOME/bin" exists by running ls -d $HOME/bin. If you get an error like bash: ls: No such file or directory. then it doesn't exist. If it does exist then you should get an output something like /home/[username]/bin.

If all those are satisfied then you should be good to go. If you're not, then just use this command: cd [path_to_studio_directory]; ./studio.sh instead. That way you will start inside that folder and guarantee its execution.

  • Why I have to add that to ~/.bashrc when I did not that here:help.ubuntu.com/community/EnvironmentVariables. Also how I can check the existence of $HOME/bin? – hasanghaforian Jan 30 '16 at 16:46
  • 1
    @hasanghaforian: That recommendation makes no sense to me either. – Gunnar Hjalmarsson Jan 30 '16 at 17:07
  • Because ~/.bashrc always gets run when you enter Terminal. It's just another check to ensure that it happens. See edit for checking existence @hasanghaforian – Daniel Jan 30 '16 at 17:14
  • 1
    If you use ~/.profile to edit PATH, which is an environmental variable, the new value is available in the whole session, whether you use the terminal or not. If you do it right, you don't need "another check". ;) – Gunnar Hjalmarsson Jan 30 '16 at 17:27
  • Well, I've run into cases where ~/.profile doesn't get processed at all, so I don't trust it as much... – Daniel Jan 30 '16 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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