This is probably a stupid question, but I recently realized that I have no idea why there's no single-user functionality with apt-get.

Answers I'm not looking for:

  • "It's because apt writes to system-level directories". This is the surface-level why, but I'm looking for a level deeper. Is there something fundamentally blocking a single-user environment (a la pip + virtualenv)?
  • "You can just build from source". This is a workaround, but does not address my question. I don't want to fix a short-term issue, and I have root access on all of my machines anyway.
  • I hope you know you can build any package from source in your home directory. – jobin Mar 28 '14 at 2:51
  • Right, but I'm looking for the why underlying the apt-get limitation. Building from source does not answer that. – PattimusPrime Mar 28 '14 at 3:01
  • 1
    I think the question you're really asking is "Why isn't most Linux software relocatable?". It would be perfectly possible to allow apt-get to install software into user-local directories, but since most software doesn't support this there would be little point in doing so. – user21322 Mar 28 '14 at 12:14

Why does apt-get require sudo?

Not always. You can perfectly use apt-get without sudo. There are instances where you don't need sudo at all, like using apt-get download which downloads a package to your current directory, apt-get source which downloads the debian sources files to your current directory, changelog which downloads and prints the changelog of a given package, and any command which has the --simulate/--dry-run/--no-act (in the case of install you need also --no-download).

This is because these actions/commands doesn't require to write system directories.

Now, why apt-get needs sudo? Actually it doesn't. You can ditch apt-get, download a package with wget and use dpkg --extract and extract the package in whatever directory you like. There's also --instdir which should work for binary only package.

Now, why this isn't the default? Because it's a pain. To do what you want, we would need to repackage each package twice, one for the right way, and another to do what you want. At build, binaries normally need to know where are the files and libraries they need (in some cases, this is hardcoded at compilation).

Now, what you can do instead? Just chroot some environment a la virtualenv, where you can install packages without root.

Summary, this is not the way that apt-get was meant to be used, and I don't know another package manager similar to apt-get which allows you to do that. At the end of the day, apt-get is just a front-end to dpkg which could do some of this.

| improve this answer | |

It's not a stupid question.

Privilege levels in an operating system

Ubuntu - and indeed any modern operating system - has the concept of different privilege levels for different software. Software initiated by users usually runs under a user-based privilege level, which for security reasons does not have the required access to modify the system - it can only modify files belonging to that user.

In order to perform any modification to the operating system which could have an impact on the system as a whole, rather than just the user's files, a higher privilege level is required, which in Linux is referred to as "superuser" privileges (or commonly called "root"). This privilege level has unfettered access to the entire operating system allowing it to modify - or destroy - all files for all users.

The role of apt-get

When you are installing software via apt-get, you are installing software that will be available system-wide. That is, the software won't just be placed into a user's home directory for running by that user only, but it will be installed in a system-wide application directory (such as in /usr, /etc, /var and so on) for running by all users. In order to modify these directories you need superuser privileges. No unprivileged user can modify these directories, because otherwise unprivileged software could mess with the system.

If you try to install something using apt-get without giving apt-get superuser privileges, the first hurdle that it will fail to overcome is to obtain a lock to write to its own software catalog. Being a system-wide utility, apt-get maintains a catalog of installed software, which naturally requires superuser privileges to edit so that unprivileged software can't mess with it. But even if you could somehow overcome this hurdle (for example, by changing file permissions), many further steps along the way of installing the software will still fail, because the installation routine will depend upon writing to several system directories.

Using Linux it is possible to install software without superuser privileges, but you need to write it yourself (eg, shell scripts) or compile it yourself and run the compiled executables directly. It is easier just to install it system-wide using apt-get (and other APT based utilities like aptitude, synaptic, or the Ubuntu software centre) if you have access to do so.

| improve this answer | |
  • Thanks for answering, and thanks for the thoroughness. I understand the system-wide nature of apt-get, but what I'm trying to understand is why it has to be that way. – PattimusPrime Mar 28 '14 at 12:16
  • 1
    It didn't have to be that way. It just happens to be the way Ubuntu (and Debian) were designed. There would be nothing stopping someone designing an operating system where the normal way of installing software was per-user. – thomasrutter Mar 28 '14 at 12:22

Information in the package itself determines where files will be installed, so you need sudo both to write to / and to change the package database.

When you are installing packages, you are installing pre-built binary files and associated configuration and meta files and scripts that are essential parts of the package. These scripts and configuration files are tightly linked to dependencies and the rest of the system. You wouldn't want to change these lightly unless you knew exactly what you are doing.

If you are on a system, say at work, where you don't have sudo access, you can compile from source and set the installation directory to your home. Then, there's no need for sudo. When you are installing from source, you are generally not changing the package database.

| improve this answer | |
  • Thanks for answering! I know and use the workarounds, but what I'm trying to figure out is why I've been using them. I believe you're saying that the issue is that the install path is hardcoded by the package maintainers - why can't this be changed? – PattimusPrime Mar 28 '14 at 2:35

Why apt-get installs to / (or similar) directories by default?

The simple reason for this is that apt-get does not decide where to install software. It is decided by the developers and coded inside the application itself.

Can I install to other directories?

Yes, you can install to other directories.For open source software, get the source, change the installation directory, compile, build and install it. There is usually an option to the included configure script that lets you specify where to install. This is usually --prefix.

But I insist on using apt-get. What to do now?

OK. There is still a way to do this with apt-get, though it would be too much for a end user. Follow the steps.

  1. Get the source.
  2. Change the installation directory to something like $HOME.
  3. Compile and build.
  4. package it into a .deb file.
  5. Create a launchpad account.
  6. Sign the ubuntu code of conduct(I'm not sure if this one is necessary).
  7. create a ppa for yourself.
  8. Upload the deb package to the ppa.
  9. add the ppa to your sources.
  10. Run sudo apt-get update.
  11. Run apt-get install package.

That was too easy/hard.Is it possible to select directory during installation?

Yes and no.

Yes because it is possible, some softwares use this method, the only one that I know is Qt5.It has a .run file which, when executed asks for installation directory among many other inputs.

No because this method does not use apt-get.

Could I do this easily some day, with apt-get?

I don't think developers of apt-get and/or developers of softwares would be interested in doing this, but some software can be developed which will do the source, change, compile, build, install steps automatically by only asking for the installation directory.

My 6th sense tells me that the command would be

apt-dont-get install pkg1 pkg2 ...
| improve this answer | |
  • Thanks for the answer - it's thorough and addresses my question. I don't understand why there would be no interest in developing single-user functionality into apt-get, however. It seems like that functionality would be highly useful in certain use cases. – PattimusPrime Mar 28 '14 at 14:07
  • Good info, but a Q&A format within the Q&A...? :) Idk, maybe you should edit into a standard format? Just a thought. – chaskes Mar 28 '14 at 14:39
  • @PattimusPrime Such cases are mostly rare, because in most cases admins install all necessary software & others don't need to install software. Also the facts that building from source is very easy & that implementing such a functionality would be useless as long as software developers don't implement it in there own software will stop apt-get developers from doing so. Also, many existing programs depend upon other programs and they search them in /usr directory.Implementing such a functionality would require change in all existing softwares that have dependencies(this no goes in thousands). – Registered User Mar 29 '14 at 3:41
  • Is a Debian policy violation to install files in $HOME. You should never do that. If anything, use /opt/package and chmod the directory instead. – Braiam Mar 29 '14 at 15:38
  • @Braiam: I have seen people recommending installing packages in $HOME/opt/ if they don't have required privilege for installing packages in /opt/.. – Aditya Mar 30 '14 at 7:10

Cause it editing files that are chmodded so you cant use them. You might be able to chmod them so you cant I dont reccomend doing that though

| improve this answer | |
  • Thanks for answering. I'm looking for why it only edits chmodded files. It seems to me that a single-user functionality would be easy to implement and immensely useful in some areas (e.g. supercomputing clusters) – PattimusPrime Mar 28 '14 at 3:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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