1

I am trying my best to have a working compiler on a fresh ubuntu installation, without having access to root privileges on the machine (my user is also not on the sudoers list). To me, this is totally non-trivial. I cannot found any portable gcc for ubuntu (or linux in general) nor any recipe to create it.

Since on a freshly installed ubuntu you don't even have make, and there's no compiler to build it, at least I found out that I could download the make-x.xx.deb file with apt-get download make (it doesn't require sudo, of course, since it just downloads the deb package), extract it with dpkg -x (dpkg -i --force-not-sudo does not work...) and manually point to the extracted binary.

I tried the same with gcc, downloading also all the packages that apt-get install would have downloaded. Unsurprisingly, it didn't work. Not even adding to PATH, LD_LIBRARY_PATH, LIBRARY_PATH, COMPILER_PATH many folders did the magic. Fixing one problem after the other, the final insurmountable error with paths tricks was /usr/bin/ld: cannot find /usr/lib/x86_64-linux-gnu/libmvec_nonshared.a

As I expected, the gcc compiler is hardcoded to look for at least one library in a place I cannot write anything (/usr/lib/...). Maybe there're also others I don't know about that would fail later.

I tried also to download a prebuilt binary of clang from the LLVM website. The problem is that the clang compiler, without any gcc installed, is completely non-functional. I can make it look to the gcc headers extracted from the .deb files above, but it finally fails because it cannot find a ld executable on the system for the linking phase (I had to remove the manually extracted gcc from the path for other problems).

So here I am, asking for suggestions: how to install gcc (or any other decent compiler/build environment) on ubuntu without admin privileges? I cannot think it's not already solved as a problem [to add fuel to the fire, on windows is easy and possible with a couple of downloads from official websites].

The only idea I came up with is to build it on another identical machine on which I have admin privileges, using the --prefix and the --disable-shared switches, and find a reasonable place to store the resulting package (after a tar.gz treatment) online. But the resulting script does not look legit, when you see it is going to download a compiler from an unknown personal website...

  • Are you familiar with the 'sudo' command? I think you need it to install a tool and/or run the build. "sudo allows a permitted user to execute a command as the superuser or another user, as spec‐ified by the security policy." – 2785528 Jan 18 '18 at 18:01
  • So, what didn't work when you did ./configure --prefix=$HOME && make && make install? That should do the job; if it doesn't, there's surely a bug. –  Jan 18 '18 at 18:22
  • As I was trying to describe, make was not available. I fixed it somehow extracting from the deb file. But then also gcc is not available. How to build gcc without another compiler? That's why I was looking for an official portable compiler, or something to bootstrap the toolchain on a per-user basis. It is possible on other systems, why not on ubuntu/linux?? With this portable compiler (whatever it is, just a sane one), I can then build my own gcc! – Stefano Sinigardi Jan 18 '18 at 18:25
  • 1
    What is really the purpose of it? Because even if you succeed you will then have a gcc in an unusual place, with many supporting files in other unusual places, and that will make it very hard to use if you want to compile other things here. I would suggest just downloading a base distribution as an archive and using it by doing a chroot in it, or some container/VM tech so that you have a new standard layout of files and enough rights to install in them what you need normaly with the distribution tool. But then it depends on how this locally compiled gcc will be used. – Patrick Mevzek Jan 21 '18 at 19:21
  • 1
    I thought every supported Ubuntu already comes with gcc. Are you really wanting g++? Building gcc from another compiler was non-trivial the last time I looked (but it's been awhile). – ubfan1 Jan 21 '18 at 20:05
  • The purpose is being able to run a long script on machines without needing admin privileges. I can test the full pipeline in windows without any admin request even if the compiler is missing, downloading and building in my folder all the missing pieces. I am not worried about gcc in an unusual place. I would just use it to build a “proper” gcc from source – Stefano Sinigardi Jan 22 '18 at 17:59
  • no gcc in my vanilla newly installed ubuntu. If I write gcc on bash, it suggests me to do a sudo apt install gcc, but I'd avoid it for my experiment. I realize now that it's becoming too complex to do, but IMHO it's strange that there's no portable gcc for Linux... – Stefano Sinigardi Jan 23 '18 at 10:55
  • I am not sure you compare equivalent things. If you have C source code, you will need a compiler, both in Windows and Linux, neither will be able to do anything with the source code without a compiler. If you have some code that runs natively on Windows but needing a compiler on Linux, then you are not comparing the same things. Also "The purpose is being able to run a long script on machines without needing admin privileges. " is confusing and has nothing to do with having a compiler per se. – Patrick Mevzek Jan 26 '18 at 20:52
  • You have this: http://pcc.ludd.ltu.se/ but this is not gcc, it is another compiler. But specifically portable. – Patrick Mevzek Jan 26 '18 at 20:54
  • And look at https://gcc.gnu.org/install/build.html section "Building a native compiler" that says: The bootstrapping process will complete the following steps: "1) Build tools necessary to build the compiler. 2) Perform a 3-stage bootstrap of the compiler. This includes building three times the target tools for use by the compiler such as binutils" But you still need make beforehand, and how will you compile make sources if you do not want to install it either? – Patrick Mevzek Jan 26 '18 at 20:58
  • On windows you can find msys2, mingw or Cygwin which are binary and installable without admin privileges, providing you a fully functional C compiler without admin privileges. On Linux there’s not a similar alternative. I am (slowly, in my free time), trying to prepare a bash script to “install” gcc in the home folder, from the .deb (not from source, since I am without a compiler) and without using dpkg apart the extraction, because I didn’t find any really working combinations of parameters that didn’t require root privileges. – Stefano Sinigardi Jan 26 '18 at 21:15
  • Unix has the philosophy to build from sources (even pushed to the extreme in some distributions) and Linux distributions on top of it provides packages already compiled hence binary stuff. You want, at the same time, not start from the sources nor install packages. Also, rereading your question, please have a look again at chroot to trick tools into some defined hierarchy when instead you are elsewhere. – Patrick Mevzek Jan 26 '18 at 21:25
  • I love to start from source, but my test was doing as much as possible without root. I managed it easily on Windows, I hate of failing on Linux. chroot unfortunately requires root privileges.... – Stefano Sinigardi Jan 26 '18 at 21:28
  • In fact, the first thing that I do on windows is to build my own compiler. And I would do the same also on Linux, after having extracted a partially working gcc, I would properly build another one from scratch and from source... – Stefano Sinigardi Jan 26 '18 at 21:29
  • chroot as in this example: https://askubuntu.com/a/193704 (look at second answer too) and https://github.com/dex4er/fakechroot . Not judging it, but you also have https://github.com/Linuxbrew/brew – Patrick Mevzek Jan 26 '18 at 21:30
  • See fakechroot! https://github.com/dex4er/fakechroot which allows to do (as non root): fakechroot fakeroot debootstrap sid /tmp/sid ; fakechroot fakeroot chroot /tmp/sid apt-get install -q hello ; fakechroot chroot /tmp/sid hello – Patrick Mevzek Jan 26 '18 at 21:31
  • You may be interested by the Gentoo Linux distribution, instead of Ubuntu, as this one is based on sources, and will recompile everything at install time... – Patrick Mevzek Jan 26 '18 at 21:35

1 Answers1

0

Finally I got notice of a way to install without admin privileges make+gcc on a freshly installed ubuntu, without having to become crazy writing my own bash scripts to extract from .deb files. I just had to rely on conda!

First, install miniconda (does not require privileges)

Second, use conda to install make, gcc, ... (all available on the anaconda official channel, also!).