30

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?

1
  • 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.
    – user459652
    Jan 30, 2017 at 23:57

3 Answers 3

39

Just copy it to /usr/local/bin.

sudo cp /path/to/profit /usr/local/bin
7
  • Also, make sure the file is marked as executable, otherwise you'll get a Permission denied error.
    – luk3yx
    Jan 31, 2017 at 1:33
  • 1
    I keep getting a "cp: /usr/bin/maude: Operation not permitted" Sep 13, 2018 at 23:05
  • @CharlieParker: sudo? Sep 13, 2018 at 23:11
  • 1
    @GunnarHjalmarsson somehow it doesn't let me in /bin or /usr/bin even with sudo...It worked once I went to /usr/local/bin.... Sep 14, 2018 at 15:11
  • 1
    @Neo, please check askubuntu.com/a/955971/789450 for your curiosity.
    – Cloud Cho
    Oct 17, 2020 at 23:53
29

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)

1
  • 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. Jan 30, 2017 at 20:34
15

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

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

step 3: profit

1
  • 2
    Hilarious and succint. Step 2.5: ???
    – GetHacked
    Feb 11, 2020 at 15:35

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