How to tell Ubuntu where to install a program and how to tell where an existing program was installed?
Does something similar apply to linux where all programs are installed in a central place
Approximate equivalents of Windows install directories in Linux
\Windows
=/bin
\Windows\System32
=/lib
and/sbin
\Program Files
=/usr/bin
and/usr/lib
I would prefer to keep all my installed programs in one place so what is the right place for this in terms of best practice. In other words what is the Linux equivalent of C:\Program Files?
That would be the directories under /usr
, specifically /usr/bin
and /usr/lib
.
And how does one always install at this location, is it just a matter of placing the tarball and running the install commands from this location?
No. Where you are when you run the install commands almost never matters.
Programs you install via
apt-get
(oraptitude
) will almost always end up appropriately in/usr
. BUT programs you compile from source andmake install
will more often end up in/usr/local/bin
,/usr/local/lib
, etc, and you may have problems with that since the user-installed path in Debian/Ubuntu is/usr
and not/usr/local
.When compiling from source, add this switch to configure:
./configure --prefix=/usr
. This way when youmake install
the files will end up in the right directoryAlso look into the
checkinstall
program, which keeps track of the files a package compiled from source installs, makes a deb file, and allows for easy uninstall/reinstall.
What about if I use sudo apt-get to install a package. How can I point to this location to tell apt-get to always install there?
apt-get
/dpkg
take care of this automatically. You can use dpkg -L name-of-package
to see all the files installed by a package and where they were installed.
Usually program are installed in a couple of directories under one top directory, called a prefix. Which top directory to use depends on who are installing, for witch purpose and who will manage the software.
The prefix /usr
is used software packed by your distribution. You should not install any other software there, because it will confuse the distribution when installing and upgrading software packed by the distribution. So please do not install your own compiled software there. That is not a good idea, unless you really know what you do. And unless you are an Debian or Ubunut developer, you usually don't. I wouldn't do that anyways.
For commercial software, the prefix /opt
is used. It's reserved for them to interfere least with distributions and the local system administrator.
For software the system administrator installs for all users, the prefix /usr/local
is used. There It's out of the way from both commercial or distribution installation and will not interfere with them. So as a system administrator you use that (if you have root privileges you are a system administrator).
If you are an ordinary user installing software for yourself, you could use your home directory as prefix, by using the --prefix
option to configure
with prefix directory "~/
" or $HOME/
. I used that a lot when I was a student. :-)
Usually software do the right thing when you execute configure
with the option --prefix
with the right value and then make; make install
.
Under any of these prefixes, you usually find these directories in a standard installation.
bin
- the executable programs, binaries.sbin
- system binaries, which usually should not be executed by ordinary users.man
- manual pages for programs, libraries and config files etc.etc
- config files with default values for the software.lib
- program libraries and data files that are dependent on architecture (like the CPU) in your computer.share
- data files that are not different on different architectures, and can be shared between different computers.var
- directories with data that changes during program execution. Like logging files etc.
Most of those directories can be used with write protected file systems to increase security. The only one that users need to write to is the var/
directory.
When the software is updated these directories obviously(?) need to have writing privileges. That can be done with a remount with write privileges during installation and then remounted with read only after installation. But this is advanced, and I only give it as an example of advanced package management.
There are also some directories directly under /
(the root directory) which don't exists under any other prefix, like /dev
, /tmp
, /proc
and /srv
(for server data directories, but they are usually under /var/lib
or /var/www
and directories like that, so you need to change configuration to use this directory. I do recommend that you do that when you are running a server. Only use /var/
for testing out a standard installation).
- Linux isn't MS Windows. There are many places to place programs you install. It depends who install and for whom. Read it in my post. Notice. RedHat uses
/usr
as Debian/Ubuntu uses/usr/local
. Learn your distribution. - Different programs have different installation methods.
--prefix
are usefull for programs usingconfigure
. Best way to know is probably to read theREADME.txt
file or something like that, which you probably are provided with in the tar archive. The tar archive can be extracted in any place, like your home directory. After the installation step are done, you could remove the extracted tar archive, if you are short of storage. But don't do that to early, unless you have tested your installation properly. - Programs installed with
apt-get
oraptitude
are always installed in the proper place for the distribution. You can't change that place.
When you install programs from a repository using the normal install, it will install to the correct place, create configuration files in the right place (functionally similar to Windows registry), and create menu entries automatically.
When you download a file (non-preferred, but often necessary when the app isn't in a repository), then the first thing you did was to run tar, equivalent to unzip on Windows. This creates the files you are most likely seeing.
Then, when you run make install, that will usually put the results in the right place, maybe create menus, but it won't erase the un-tarred files. You can most likely do that, but you may want to save them temporarily just in case.
Here is an interesting article on Debian Directory Structure.