I've written a few different answers on Linux.org that address this issue.
Personally, I'd set up a personal bin directory in your home directory and copy the programs into there.
See the spoilers in this old post, which includes all of the information you'll need to set up a personal bin directory and add it to $PATH:
I've spent a half hour Googling about making an .sh executable but not found anything that works in my system. I'm trying to install/run/make executable the script at this link for saving/restoring desktop icon positions: http://www.chateaumezcal.com/software/desktop_maven.htm I'm to the part...
linux.org
Once you have a personal bin directory set up, you can simply add any programs or scripts that you want to run to that directory and because they are in $PATH, you can run them from anywhere in the file-system.
If copying the executables to the personal bin directory causes problems at runtime - e.g. getting errors about libraries not found. But the executables run OK wherever they are originally located, then you have a couple of additional options.
A. Put a symbolic link in your personal bin directory that points to the actual location of the program.
e.g.
Bash:
ln -sT /path/to/someProgram/bin/someProgram ~/bin/someProgram
Where
/path/to/someProgram/bin/someProgram
is the path to the executable file/script you downloaded and
~/bin/someProgram
is the path/name of the symbolic link to add to your personal bin directory (which will be at
~/bin/
).
That way, your symbolic link in your personal directory will be in $PATH and points directly to the executable you want to run.
Or if using a symbolic link still brings up error messages:
B. Remove the symbolic link and write a 'wrapper' script in your personal bin directory.
Bash:
#!/usr/bin/env bash
cd /path/to/someProgram/bin/
./someProgram
cd -
Save that in your personal bin directory as
someProgram
and make it executable using
chmod +x ~/bin/someProgram
.
That
cd
's into the directory containing the application (making it the current working directory), then runs the program in the current working directory.
After the program is finished, it
cd
's back to the original directory it was in before.
Then, when you want to run someProgram (from anywhere in the file-system) your wrapper script will be ran, which will cd into the directory containing the application and will then run it inside that directory.
And again -
/path/to/someProgram/bin/
should be the path to the directory containing the executable you want to run.
e.g.
~/Downloads/someProgram-v0.1/build/bin/
And
./someProgram
is the name of the script/program to run in the above directory.
Also, if the program takes parameters - you could amend the script to pass parameters to the script/program you're running:
Bash:
#!/usr/bin/env bash
cd /path/to/someProgram/bin/
./someProgram "$@"
cd -
That way you'll be able to pass parameters to your script and your script will pass all of the parameters it receives to the program.
I tend to download a lot of programs and tools as source code and build and install them from source.
Most of the time, they have install scripts, so I will run
make install
and they will install to somewhere on $PATH.
But sometimes there is no install target in the build system, or perhaps I simply want to run them from my personal bin directory. So I will use one of the strategies above.
Most of the time, simply copying the newly built executable from the source-code to the personal bin directory works.
Although sometimes I do use a symbolic link to the built executable. One advantage of using the symbolic link is that you don't have duplicate files everywhere!
But if you update from git and rebuild the program and it fails, then your symbolic link will be broken - so it's swings and roundabouts with those two options!
In other cases, if the program links to libraries, or other assets that are in the programs source-tree - I'd have to put a wrapper script into my personal bin directory.
So once you have set up a personal bin directory, there are three main ways of getting your custom programs/scripts to run.