276

Occasionally I install applications manually, rather than using apt or another package manager.

What location (/usr/, /usr/local/, /opt/, /home/, etc.) is suggested by "best practices" for the installation of user applications?

4

6 Answers 6

229

That depends, really. If the application has a makefile, or for example for Python apps if the application uses distutils (e.g., has a setup.py file), or a similar build/install system, you should install it into /usr/local/. This is often the default behavior.

From what I understand, /usr/local/ has a hierarchy that is similar to /usr/. However, directories like /usr/bin/ and /usr/lib/ are usually reserved for packages installed via apt. So a program expecting to get "installed" into /usr/ should work fine in /usr/local/.

If you just need to extract a tarball and run directly (e.g. Firefox) then put it into /opt/. A program that just needs one directory and will get all files/libraries relative to that directory can get one directory for itself in /opt/.

For reference, see the FHS.

6
  • 4
    Make a symlink from /usr/bin or add it to PATH in ~/.bashrc
    – Alex
    Jun 25, 2014 at 2:24
  • 2
    What about ~/.local/share ? @Marco Feb 9, 2019 at 15:43
  • 2
    You can install things inside ~ (your home directory), but that will make an application accessible only to one user. Other users on your system will have to install and maintain their own installations of that software. As for best practices on installing applications install your home directory, I believe there aren't as strong guidelines because you won't interfere with system packages.
    – Umang
    Feb 10, 2019 at 16:43
  • 1
    Is it wrong to install apps that are 'unzipped from tar' under /home/ubuntu/myapp - what diff does this made compared with /opt/myapp?
    – JARC
    Jul 2, 2019 at 14:20
  • 2
    @JARC, that would only be available to one user on the system (in your case the "ubuntu" user).
    – Umang
    Jul 2, 2019 at 20:36
149

It's good to remember that /usr does not stand for user but rather unix system resources.

As such, I tend to figure that any distribution has the rights to stomp all over over contents of /usr, and that my specific additions to the system go in /usr/local, which I preserve before doing an upgrade.

Meanwhile, applications and other things go in /opt.

Some people feel comfortable putting stuff in /home, though I rarely follow that convention.

All that said, I let the distribution package manager do things its way first, and then do the above when hand rolling stuff.

6
  • 48
    It's worth remembering that 'unix system resources' is a renaming performed AFTER '/home' was added. In the old, old, old days (Unix Version 6 et.al.) you would see directories like /usr/jimmy, /usr/siobhan, /usr/ahmed, etc. because the "user" directories were stored in /usr. Nov 20, 2012 at 18:52
  • 10
    OK I'll bite: what does opt stand for?
    – Seth
    May 12, 2015 at 2:17
  • 6
    @Seth I think it's 'optional' - it was originally for software that wasn't part of a default installation.
    – Carl H
    Jun 13, 2015 at 14:53
  • 10
    /usr is User. That was because linux users were developers. First as it started to devide into devs and users the /home dir was introduced. And then someone had the idea to say it means Unix System Resources, which doesn't really makes sense, because we have the Unix system Resources in /dev Dec 17, 2016 at 14:47
  • 5
    Correct, /usr is a backronym. The purpose has changed since the days Unix was running on a PDP-7 back in 1969. Dec 28, 2017 at 17:57
45

Install unstable programs like firefox devel in /home/user/opt/ makes it a lot easier to remove, and no confusion for other users as to what version they should use... So if it is not a program for global use, install it in a subfolder in your home directory (/home/user/).

Never install programs in /usr/, it is likely to cause chaos, things installed in /usr/ is meant to be for distribution packages only. /usr/local/ is for packages locally compiled. And the structure works in exactly the same way! files in /usr/local/ will be prioritized over files in /usr/.

/opt/ should be used for installation of pre-compiled (binary) packages (Thunderbird, Eclipse, Netbeans, IBM NetSphere, etc) and the like. But if they are only for a single user they should be put in your home directory.

If you want to be able to run a program installed in a "weird" location (like /home/user/opt/firefox/) without typing the whole path you need to add it to your $PATH variable, you can do this be adding a line like this in your /home/user/.profile

export PATH=/home/user/opt/firefox:$PATH

The folder name should be the one where the executable file you need to run is located.

29

The Linux Filesystem Hierarchy Standard indicates /usr/local.

From http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/usr.html:

The original idea behind '/usr/local' was to have a separate ('local') '/usr' directory on every machine besides '/usr', which might be just mounted read-only from somewhere else. It copies the structure of '/usr'. These days, '/usr/local' is widely regarded as a good place in which to keep self-compiled or third-party programs. The /usr/local hierarchy is for use by the system administrator when installing software locally. It needs to be safe from being overwritten when the system software is updated. It may be used for programs and data that are shareable amongst a group of hosts, but not found in /usr. Locally installed software must be placed within /usr/local rather than /usr unless it is being installed to replace or upgrade software in /usr.

1
  • 5
    Seems to contradict this /usr/local stuff with the info on the opt page: tldp.org/LDP/Linux-Filesystem-Hierarchy/html/opt.html " "This directory is reserved for all the software and add-on packages that are not part of the default installation. For example, StarOffice, Kylix, Netscape Communicator and WordPerfect packages are normally found here. To comply with the FSSTND, all third party applications should be installed in this directory." ... " (similar to the way in which Windows will install new software to its own directory tree C:\Windows\Progam Files\"Program Name")"
    – Pod
    Aug 4, 2016 at 11:15
8

I usually have a folder named "Programs" in my home where I install those programs, strange enough (or not) they are all java stuff right now.

It has one great advantage for me, when I reinstall or change computers they get moved with the rest of my home. It has a clear disadvantage, those apps are only available to my user.

1
  • How can i reinstall Ubuntu 16.04 without losing data in home folder ? I tried to do by formate / directory only then type the same old username and password but i found that Ubuntu creates another home folder. Dec 30, 2017 at 14:56
1

Use "checkinstall" to convert your alien package to a deb so that it is uninstallable using the package manager.

Do note that config files will often not be handled as config files (perhaps ignored, or perhaps treated as part of the app), and that pre- and post-install scripts sometimes get bungled, though it will usually warn you when it thinks the deb will have a bad pre- or post-install script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .