How to tell Ubuntu where to install a program and how to tell where an existing program was installed?

I'm totally new to Ubuntu/Linux, using Ubuntu Server at the moment. Just trying to figure out something basic.

How can you tell where you are installing a program. For example I just installed Sphinx search engine by placing the tarball that I downloaded from their site in /home/sphinx. I created the sphinx directory to place that tarball in. Then I ran these commands:

tar xvzf sphinx-0.9.8.1.tar.gz
cd sphinx-0.9.8.1/
./configure --with-mysql-includes=/usr/include/mysql --with-mysql-libs=/usr/lib/mysql

and then these:

make
sudo make install

Now I have a lot of files sitting in the directory where I ran these commands. Is this my Sphinx installation or did it install somewhere else?

In Windows if you run an installer (.exe file) anywhere the program will still install in your C:\\Program Files directory. Does something similar apply to Linux where all programs are installed in a central place, or can you install programs anywhere on the system?

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?

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?

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?


Solution 1:

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 (or aptitude) will almost always end up appropriately in /usr. BUT programs you compile from source and make 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 you make install the files will end up in the right directory

  • Also 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.

Solution 2:

Usually programs are installed in a couple of directories under one top directory, called a prefix. Which top directory to use depends on who is installing, for what 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.

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.

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 does 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 log 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 need to have write privileges. Usually one does not need to do anything, but if needed 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).

Different programs have different installation methods. --prefix is useful for programs using configure. Best way to know is probably to read the README.txt file or something like that, which is probably provided with in the tar archive.

The tar archive can be extracted in any place, like your home directory. After the installation steps are done, you can remove the extracted tar archive if you are short of storage. But it's better to keep the directory as you can often use it for uninstallation.

Programs installed with apt-get or aptitude are always installed in the proper place for the distribution. You can't change that place.

Solution 3:

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.