14

I have an sh file that I would like to be able to open from the terminal at any time. I would like to type "studio" into the terminal, and have android studio open

I recall using ln -s to do this, but I have forgotten and have already wasted much time searching the web.

Also, in which directory is the created symbolic link kept in?

Here is the syntax from my effort, command not found

ricardo@debian:~$ ln -s /opt/android-studio/bin/studio.sh studio
ricardo@debian:~$ studio
bash: studio: command not found
9
  • try ./studio.
    – Sebastian
    Aug 29, 2015 at 18:47
  • I want to make a link to ./studio that I can open from anywhere by simply typing in studio, or banana
    – rickyjoepr
    Aug 29, 2015 at 18:48
  • If you want to execute the script from anywhere using studio alone, you have to put the link in a place that is being searched by the shell. The shell searches everything in echo $PATH. You can either change $PATH or put the link into one the directories of $PATH. What do you prefer?
    – Sebastian
    Aug 29, 2015 at 18:51
  • 4
    @Sebastian Please use answers to answer questions, not comments. And please do not suggest deleting questions after they've been answered. We're here to build a repository of answers that stay around and are useful to future visitors. Aug 29, 2015 at 19:27
  • 1
    You may like the alias command, which is commonly used instead of creating symbolic links to shorten command names.
    – Winny
    Aug 29, 2015 at 19:48

2 Answers 2

14

The command you ran created a symbolic link in the current directory. Judging by the prompt, the current directory is your home directory. Creating symbolic links to executable programs in your home directory is not particularly useful.

When you type the name of a program, the shell looks for it in the directories listed in the PATH environment variable. To see the value of this variable, run echo $PATH. The directories are separated by a colon (:). A typical path is /home/ricardo/bin:/usr/local/bin:/usr/bin:/bin but there's a lot of variation out there.

You need to create this symbolic link in one of the directories listed in $PATH. If you want to make the command available to all users, create the link in /usr/local/bin:

sudo ln -s /opt/android-studio/bin/studio.sh /usr/local/bin/studio

If you want to make the command available only to you (which is the only possibility if you don't have administrator privileges), create the link in ~/bin (the bin subdirectory of your home directory).

ln -s /opt/android-studio/bin/studio.sh ~/bin/studio

If your distribution doesn't put /home/ricardo/bin in your PATH (where /home/ricardo is your home directory), create it first with mkdir ~/bin, and add it to your PATH by adding the following line to ~/.profile (create the file if it doesn't exist):

PATH=~/bin:$PATH

The .profile file is read when you log in. You can read it in the current terminal by running . ~/.profile (this only applies to programs started from that terminal).

3
  • 1
    +1 but as Winny's comment, I think an alias in ~/.bashrc would be more straightforward.
    – Sparhawk
    Aug 30, 2015 at 2:23
  • @Sparhawk An alias would only work to invoke the program from an interactive shell, not from a script, a desktop shortcut, or any other program. Aug 30, 2015 at 7:36
  • 1
    True, but the question states I would like to type "studio" into the terminal, and this is implied from the title and quoted commands.
    – Sparhawk
    Aug 30, 2015 at 8:46
3

The most intuitive way to implement your wish is to use an alias. Type:

alias studio=/opt/android-studio/bin/studio.sh

or enter a related alias into .profile or better: what your shell uses as $ENV.

Note that you still may need to add

/opt/android-studio/bin

to your PATH to be able to use the software. The best is to first try out whether it works without an extended PATH.

You must log in to answer this question.

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