5

In the installation instructions for Android Studio they say:

3. [OPTIONAL] Add "{installation home}/bin" to your PATH environment
 variable so that you may start Android Studio from any directory.

I did that according to this Stack Overflow question. But how do I start it now? The problem is I need to execute a shell script studio.sh and I am afraid these are not visible for the PATH variable.

I should be able to call it in any directory in terminal by calling just studio.sh.

EDIT: more info

studio.sh runs the Android Studio

I followed the official installation instruction which came with the android-studio zip file (form official website).

I added

export PATH=$PATH:$HOME/Installs/android-studio/bin

at the end of ~/.profile.

Adding more outputs:

$ ls -l $HOME/Installs/android-studio/bin/studio.sh
-rwxr-xr-x 1 roman roman 6985 bře 21 18:26 /home/roman/Installs/android-studio/bin/studio.sh

$ echo $PATH
/home/roman/bin:/home/roman/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/roman/Installs/android-studio/bin/studio.sh

$ type studio.sh
bash: type: studio.sh: not found
  • What is the output from locate studio.sh? – WinEunuuchs2Unix Mar 31 '18 at 22:04
  • I returns 1. No output. – SlowerPhoton Mar 31 '18 at 22:07
  • @win type studio.sh might work better – wjandrea Mar 31 '18 at 22:09
  • @wjandrea type -a studio.sh might work even better :D – WinEunuuchs2Unix Mar 31 '18 at 22:10
  • It says bash: type: studio.sh: not found. I guess this implies it's not in the PATH after all. I updated the question to show the instructions I followed. The path to studio.sh is certainly correct - I tested it with cd. – SlowerPhoton Mar 31 '18 at 22:13
  • @SlowerPhoton which and type will only find executables in the path. But to add it to the path we need to know what directory it is in. For this locate studio.sh always works unless it isn't even installed on your system. – WinEunuuchs2Unix Mar 31 '18 at 22:16
  • @win locate uses a database that's not updated immediately. I think you want to use find instead, e.g. find ~ -name studio.sh -type f – wjandrea Mar 31 '18 at 22:20
  • I don't what you mean by 'installed'. I can run android studio with this shell script, so I'd say it is installed. And we know the directory it is in: $HOME/Installs/android-studio/bin. – SlowerPhoton Mar 31 '18 at 22:21
  • I think my question must be too confusing somehow. Sorry for that. I know the directory it (studio.sh) is in, how would I add it to the PATH otherwise? – SlowerPhoton Mar 31 '18 at 22:23
  • @SlowerPhoton What is the output of ls -l $HOME/Installs/android-studio/bin/studio.sh? And the output of echo $PATH? – wjandrea Mar 31 '18 at 22:25
  • @wjandrea true if just installed today the updatedb command would have to be run first. – WinEunuuchs2Unix Mar 31 '18 at 22:26
  • After running updatedb locate now finds it. Where are we heading with this? – SlowerPhoton Mar 31 '18 at 22:33
  • @SlowerPhoton OK, then something doesn't add up. The script is executable, in the path, and the PATH is correct, but Bash doesn't find it. – wjandrea Mar 31 '18 at 22:33
  • Ok, I realize my question was indeed too confusing. I'll try to rephrase it. I want to be able to call the script in any directory from terminal. Easily. So nothing like /path/to/studio.sh but instead something simple like bash studio.sh or ./studio.sh. I believe that is possible because of the installation instructions (see it in the question). – SlowerPhoton Mar 31 '18 at 22:36
  • This question had a similar solution: How to set $PATH in Ubuntu – wjandrea Mar 31 '18 at 23:02

2 Answers2

3

This is the last item in your PATH:

/home/roman/Installs/android-studio/bin/studio.sh

The problem is that items in the PATH need to be directories but you've added a file. I'm not sure how this happened since it doesn't match the export PATH=... line you posted.

wjandrea
  • 14,236
  • 4
  • 48
  • 98
0

First find out what directory studio.sh is in so you can add it to the path. Consider the following:

rick@alien:~$ locate --regex "wpasupplicant$"
/etc/network/if-down.d/wpasupplicant
/etc/network/if-post-down.d/wpasupplicant
/etc/network/if-pre-up.d/wpasupplicant
/etc/network/if-up.d/wpasupplicant
/lib/systemd/system-sleep/wpasupplicant
/mnt/e/lib/systemd/system-sleep/wpasupplicant
/usr/share/doc/wpasupplicant
/usr/share/lintian/overrides/wpasupplicant
───────────────────────────────────────────────────────────────────────────────────────────
rick@alien:~$ which wpasupplicant
───────────────────────────────────────────────────────────────────────────────────────────
rick@alien:~$ type wpasupplicant
bash: type: wpasupplicant: not found
───────────────────────────────────────────────────────────────────────────────────────────
rick@alien:~$ ll /lib/systemd/system-sleep/wpasupplicant
-rwxr-xr-x 1 root root 182 Oct 26  2015 /lib/systemd/system-sleep/wpasupplicant*

The file wpasupplicant is defined as an executable as defined by the x in -rwxr-xr-x.

There is also a remote possibility studio.sh isn't defined as an executable and still in the path. In this case the which and type commands will not find it but the locate command will still find it.

If the file was just created

Consider if the file was just created:

rick@alien:~$ cp .rm-kernels-ndx asdf.asdf
───────────────────────────────────────────────────────────────────────────────────────────
rick@alien:~$ locate asdf.asdf
───────────────────────────────────────────────────────────────────────────────────────────
rick@alien:~$ time sudo updatedb

real 0m3.460s user 0m0.503s sys 0m1.167s ─────────────────────────────────────────────────────────────────────────────────────────── rick@alien:~$ locate asdf.asdf /home/rick/asdf.asdf

You need to run sudo updatedb for locate command to find newly created files. The program updatedb is called automatically by cron but newly created files may not appear. After comments on this thread I decided to change my own sudo crontab -e to run /usr/bin/updatedb every five minutes.

After you find the directory

To add your directory to the path edit ~/.profile and add the following:

if [ -d "$HOME/Installs/android-studio/bin" ] ; then
  PATH="$PATH:$HOME/Installs/android-studio/bin"
fi
  • studio.sh is defined as an executable. There are three "x"s. – SlowerPhoton Mar 31 '18 at 22:25
  • So the locate command found it? What directory is it in? – WinEunuuchs2Unix Mar 31 '18 at 22:27
  • Sorry but I don't think you've read the question. In $HOME/Installs/android-studio/bin directory. I knew it from the beginning and it is unimportant for what I want to achieve. I want to be able to type studio.sh anywhere in terminal (in any directory) and start Adroid Studio. – SlowerPhoton Mar 31 '18 at 22:30
  • @SlowerPhoton Sorry I missed that edit. – WinEunuuchs2Unix Mar 31 '18 at 22:32
  • @win Forget updatedb, just don't use locate. It's less flexible than find anyway. Use find ~ -name studio.sh instead. – wjandrea Mar 31 '18 at 22:32
  • @wjandrea the point is locate is blazingly fast across multiple partitions and drives including ntfs partitions as it doesn't have to navigate directories. – WinEunuuchs2Unix Mar 31 '18 at 22:33
  • But why? I know where it is. I don't want to argue with you. I am glad for your help. It's just that I don't understand why. – SlowerPhoton Mar 31 '18 at 22:34
  • 1
    @SlowerPhoton I added how to correctly add the path to the answer. After this your type studio.sh should find it. – WinEunuuchs2Unix Mar 31 '18 at 22:39
  • It is already in the PATH variable. And I have updated ~/.profile already - I also used export PATH which I believe is necessary. All in all neither this was the original question. Let me rephrase it, because it seems to be too confusing. I want to be able to call the script in any directory from terminal. Easily. So nothing like /path/to/studio.sh but instead something simple like bash studio.sh or ./studio.sh. I believe that is possible because of the installation instructions (see it in the question). – SlowerPhoton Mar 31 '18 at 22:44
  • As long as studio.sh is executable it will be called. To confirm your export worked as expected use echo $PATH in the command line. – WinEunuuchs2Unix Mar 31 '18 at 22:50
  • Thanks I've resolved it by now. The problem was indeed the PATH variable. – SlowerPhoton Mar 31 '18 at 23:00
  • @SlowerPhoton Yes I caught that on wjandrea's answer. I was busy with crontab and missed your edit 10 minutes ago where you accidentally had the file name in the path. – WinEunuuchs2Unix Mar 31 '18 at 23:05