This question already has an answer here:

I have a load of tools that are kept in the /opt directory. The tools are organised like this: /opt/toolname/tool.sh. My question is, how can I add the tools in my /opt folder to my path, so i can run them from any directory in a terminal.

I have managed to do this with some tools by creating a symlinks in /usr/bin; but with over 200 tools it is a very tedious way of doing things. is there a better way to do this?

marked as duplicate by slm Feb 6 '15 at 13:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Sorry, $PATH isn't recursive -- and IMO, shouldn't be, so you may be out of luck. Best advice I can add would be to write a tool that keeps your symlinks in order. – Shadur Feb 6 '15 at 11:58

The only correct way, is to make links in /usr/bin or /usr/local/bin as you described. Because in those folders in /opt/toolname there are normally many other files, not just executables. I would be grubby. Anyway, adding /opt/*/ to the $PATH variable would not work.

If you have a list of the full paths to those binaries, you could generate the links scriptually.

  • 5
    Just /usr/local/bin. /usr/bin is managed by package managers and it's not idea to put out-of-package links there. – orion Feb 6 '15 at 12:02
  • Yes, politically correct it would only be /usr/local/bin ^^ – chaos Feb 6 '15 at 12:02

There are many ways to do it:

  1. Make a symlink in /usr/bin (or /usr/local/bin) directory sudo cp -s /opt/toolname/tool.sh /usr/bin/[unique_Toolname]
  2. Add /opt/toolname/tool.sh to $PATH variable export $PATH=$PATH:/opt/toolname/
  3. Combine the above but use $HOME/.local/share/bin instead system /usr/bin

You can add the folders to your path using the following command:

export PATH=/path/to/folder:$PATH

You should include this in a shell script that will be run before you open a terminal window (such as .bash_profile in your home folder).

However, since path isn't recursive, you'll need to add each individual tool folder.


Thanks to all for the feedback and your time. You have confirmed what I suspected, there is no one click solution to this problem. I will be continuing down my original route and manually add the symlinks for now, this time to /user/local/bin.

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