Linux user programs directory

When installing user applications, where do «best practices» suggest they be located?

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?

Liking to install things from source every so often, I wrote a little tool to do it which does the changes to your shell startup file on its own (and also modify your library prefix, if you ask it, for programs that depend on shared libraries). Not very feature rich, but it works 99% of the time.

Great discussion on the distinction between /opt and /usr/local : unix.stackexchange.com/q/11544/11917

6 Answers 6

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/ .

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.

Is it wrong to install apps that are ‘unzipped from tar’ under /home/ubuntu/myapp — what diff does this made compared with /opt/myapp?

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.

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.

Читайте также:  Linux add user permissions to folder

@Seth I think it’s ‘optional’ — it was originally for software that wasn’t part of a default installation.

/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

Correct, /usr is a backronym. The purpose has changed since the days Unix was running on a PDP-7 back in 1969.

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.

Источник

Linux Directory Structure Explained for Beginners

This tutorial explains the Linux directory structure. You’ll learn the Linux filesystem hierarchy along with the purpose of the various directories on a Linux system.

If you are even faintly acquainted with Linux, you might have heard the terms root, lib, bin etc. These are various directories that you’ll find in all Linux distributions.

In fact, the Linux Foundation maintains a Filesystem Hierarchy Standard (FHS). This FHS defines the directory structure and the content/purpose of the directories in Linux distributions. Thanks to this FHS, you’ll find the same directory structure in (almost) all the Linux distributions.

Let’s see the Linux directory structure in detail.

Linux directory structure

Linux is based on UNIX and hence it borrows its filesystem hierarchy from UNIX. You’ll fine a similar directory structure in UNIX-like operating systems such as BSD and macOS. I’ll be using the term Linux hereafter instead of UNIX though.

/ – The root directory

Everything, all the files and directories, in Linux are located under ‘root’ represented by ‘/’. If you look at the directory structure, you’ll realize that it is similar to a plant’s root.

Linux Directory Structure

Since all other directories or files are descended from root, the absolute path of any file is traversed through root. For example, if you have a file in /home/user/documents, you can guess that the directory structure goes from root->home->user->documents.

The cruel rm -rf / joke

You may have come across some jokes on internet that mentions “rm -rf /” . rm command is used for removing files and directories in Linux.

Читайте также:  Спящий режим монитора linux

With rm -rf /, you ask your system to forcefully and recursively delete the contents of the root directory. Since root directory has everything underneath, you end up deleting everything and your Linux system just vanishes (theoretically).

Most Linux distribution won’t run this command unless you provide –no-preserve-root. In any case, don’t be curious to run this command. Curiosity killed the cat, after all.

/bin – Binaries

The ‘/bin’ directly contains the executable files of many basic shell commands like ls, cp, cd etc. Mostly the programs are in binary format here and accessible by all the users in the Linux system.

/dev – Device files

This directory only contains special files, including those relating to the devices. These are virtual files, not physically on the disk.

Some interesting examples of these files are:

  • /dev/null: can be sent to destroy any file or string
  • /dev/zero: contains an infinite sequence of 0
  • /dev/random: contains an infinite sequence of random values

/etc – Configuration files

The /etc directory contains the core configuration files of the system, use primarily by the administrator and services, such as the password file and networking files.

If you need to make changes in system configuration (for example, changing the hostname), this is where you’ll find the respective files.

/usr – User binaries and program data

in ‘/usr’ go all the executable files, libraries, source of most of the system programs. For this reason, most of the files contained therein is read­only (for the normal user)

  • ‘/usr/bin’ contains basic user commands
  • ‘/usr/sbin’ contains additional commands for the administrator
  • ‘/usr/lib’ contains the system libraries
  • ‘/usr/share’ contains documentation or common to all libraries, for example ‘/usr/share/man’ contains the text of the manpage

/home – User personal data

Home directory contains personal directories for the users. The home directory contains the user data and user-specific configuration files. As a user, you’ll put your personal files, notes, programs etc in your home directory.

When you create a user on your Linux system, it’s a general practice to create a home directory for the user. Suppose your Linux system has two users, Alice and Bob. They’ll have a home directory of their own at locations /home/alice and /home/bob.

Do note that Bob won’t have access to /home/alice and vice versa. That makes sense because only the user should have access to his/her home. You may read about file permissions in Linux to know more on this topic.

/lib – Shared libraries

Libraries are basically codes that can be used by the executable binaries. The /lib directory holds the libraries needed by the binaries in /bin and /sbin directories.

Libraries needed by the binaries in the /usr/bin and /usr/sbin are located in the directory /usr/lib.

/sbin – System binaries

This is similar to the /bin directory. The only difference is that is contains the binaries that can only be run by root or a sudo user. You can think of the ‘s’ in ‘sbin’ as super or sudo.

Читайте также:  Переименовать файл командная строка linux

/tmp – Temporary files

As the name suggests, this directory holds temporary files. Many applications use this directory to store temporary files. Even you can use directory to store temporary files.

But do note that the contains of the /tmp directories are deleted when your system restarts. Some Linux system also delete files old files automatically so don’ store anything important here.

/var – Variable data files

Var, short for variable, is where programs store runtime information like system logging, user tracking, caches, and other files that system programs create and manage.

The files stored here are NOT cleaned automatically and hence it provides a good place for system administrators to look for information about their system behavior. For example, if you want to check the login history in your Linux system, just check the content of the file in /var/log/wtmp.

/boot – Boot files

The ‘/boot’ directory contains the files of the kernel and boot image, in addition to LILO and Grub. It is often advisable that the directory resides in a partition at the beginning of the disc.

/proc – Process and kernel files

The ‘/proc’ directory contains the information about currently running processes and kernel parameters. The content of the proc directory is used by a number of tools to get runtime system information.

For example, if you want to check processor information in Linux, you can simply refer to the file /proc/cpuinfo. You want to check memory usage of your Linux system, just look at the content of /proc/meminfo file.

/opt – Optional software

Traditionally, the /opt directory is used for installing/storing the files of third-party applications that are not available from the distribution’s repository.

The normal practice is to keep the software code in opt and then link the binary file in the /bin directory so that all the users can run it.

/root – The home directory of the root

There is /root directory as well and it works as the home directory of the root user. So instead of /home/root, the home of root is located at /root. Do not confuse it with the root directory (/).

/media – Mount point for removable media

When you connect a removable media such as USB disk, SD card or DVD, a directory is automatically created under the /media directory for them. You can access the content of the removable media from this directory.

/mnt – Mount directory

This is similar to the /media directory but instead of automatically mounting the removable media, mnt is used by system administrators to manually mount a filesystem.

/srv – Service data

The /srv directory contains data for services provided by the system. For example, if you run a HTTP server, it’s a good practice to store the website data in the /srv directory.

I think this much information is enough for you to understand the Linux directory structure and its usage.

In the end, if you want, you can download and save this image for quick reference to the directory structure in Linux systems.

Источник

Оцените статью
Adblock
detector