35

I realise this is basic but I have read two pages of google answers and am still unclear 'How to put executable in /usr/local/bin?'

I have downloaded a package and made the executable called profit. What is the step by step command line to make profit executable from the terminal without having to add the path/to/profit every time?

muru
  • 197,895
  • 55
  • 485
  • 740
  • By "package" do you mean just some source files, or do you mean a autoconf / configure package of some sort? The latter often have an install target that does all the right things for installing executables and support files. –  Jan 30 '17 at 23:57

3 Answers3

44

Just copy it to /usr/local/bin.

sudo cp /path/to/profit /usr/local/bin
Gunnar Hjalmarsson
  • 33,540
  • 3
  • 64
  • 94
34

There are various things to consider; just for completeness:

First of all, you should make sure that this executable has in fact the required permissions.

sudo chmod a+rx /path/to/profit

(for example when extracting archives that were thrown together using the zip tool, permissions can get lost)

Then you can either copy the file as Gunnar suggested; or you can create a symbolic link:

sudo ln -s /path/to/profit /usr/local/bin

Depending on your context, using a link might be more convenient in the future; on the other hand it carries some security risks (for example when /path/to/profit can be written by non-root users)

GhostCat
  • 2,095
  • 1
    The symbolic link definitely eases things if you expect to be doing frequent upgrades (eliminating the need to copy the binary there each time), and can save the need to also copy any other binaries it calls from its "home" directory, so it's worth it to set permissions on the real path to not be writable other than by root. – Monty Harder Jan 30 '17 at 20:34
18

step 1: chmod +x /path/to/profit

step 2: sudo cp /path/to/profit /usr/local/bin/

step 3: profit