39

I downloaded the Google App Engine as a zip format, unzipped it to /usr/local/google_engine

Now I need to run a python script from that folder all the time. How do I make it available no matter where my path is? ie: when i'm in /usr/something/ i can execute the script by just calling script.py?

Can I do this without aliasing or without using bash scripts?

1
  • 2
    Set your PATH? Like export PATH=$PATH:/usr/local/google_engine
    – wkl
    Apr 19, 2012 at 19:14

2 Answers 2

71

Edit your .bashrc to add the desired directory on the PATH environmental variable.

export PATH=/usr/local/google_app_engine/bin:$PATH

then, either start new terminal or do,

source ~/.bashrc

Now try to run the script from anywhere.

Another way you can do it without even touching the .bashrc would be to create a symlink by doing something like,

sudo ln -s /usr/local/google_app_engine/bin/script.py /usr/bin/script.py 
5
  • 3
    Shouldn't it be ln -s /usr/local/google_app_engine/bin/script.py /usr/bin/script.py? The destination with ln, as with most commands, is the last parameter.
    – rodrigo
    Apr 19, 2012 at 19:34
  • It's easy to remember if you think that it works just like cp.
    – rodrigo
    Apr 19, 2012 at 19:44
  • 3
    Why can't I just copy the binary files to /usr/bin/?
    – Alston
    May 9, 2015 at 9:23
  • sudo ln -s /usr/local/google_app_engine/bin/script.py /usr/bin/script.py Rocks! Jun 21, 2016 at 11:56
  • zsh: too many levels of symbolic links: /usr/bin/script.py
    – alper
    Aug 12, 2021 at 17:30
6

There are two ways to do this. As Kal mentioned above you can add the folder to the path variable by adding

export PATH=/usr/local/google_app_engine/bin:$PATH1 

to your .bashrc. Alternatively, if the command is just one script you can move or copy it to /usr/bin. This will make it accessible as a command from anywhere.

If you want to create a command to do this without moving script.py then you can create a bash file that calls it with a fixed path then put that in /usr/bin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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