Install gcc on linux with no root privilege

43,167

Solution 1

You can run the configure script with the --prefix parameter: ../gcc-4.5.0/configure --prefix=/home/foo/bar. Since it is very likely that the c++ standard library is different then the one on your system, you have to set export LD_LIBRARY_PATH=/home/foo/bar/lib before you can start a program compiled by this compiler.

Solution 2

If you want to install it as a local user

GNU GSRC provides an easy way to do so

Link: http://www.gnu.org/software/gsrc/

After configuration, simply specify the following commands:

cd gsrc
make -C pkg/gnu/gcc 
make -C pkg/gnu/gcc install

The second step could also be changed to speed up for an N-core system:

make -C pkg/gnu/gcc MAKE_ARGS_PARALLEL="-jN"

Solution 3

Once, a long time ago (1992 or so), I went through something similar to this when I bought a SCO system with no development environment. Bootstrapping it up to having a full development environment was a gigantic pain, and not at all easy. Having library header files or gcc on a system would make your job a whole lot easier.

It depends a lot on just how obnoxious the library has been about what kinds of things are installed. If there is no gcc there, your job becomes a bit harder. If there are no header files for glibc there, your job is a LOT harder.

Also, do you get an account on the system so you have a home folder that's consistent from login to login?

If you have no gcc there, you need to find a pre-compiled binary of gcc/g++ and install it somewhere. If you have no header files there, you need to find copies of those and put them on the system.

There is no 'standard' way of installing gcc in your home folder though. All of the solutions are going to have some manner of hand-rolling involved.

Have you asked the librarians if they can change what's installed because you want to learn a bit of programming and only have access to their computers to do it with? That might well be the easiest solution.

From your comment it seems that you do have gcc and if you can compile C code, you have the library header files. So now it's a matter of actually compiling your own version of g++. You could probably find a way to entice the package manager on the system into installing a binary package somewhere other than in a system folder. I think this solution is less fun than compiling your own, and I think there may also be possible subtle problems as that installed package may be expecting to find things in particular places and not finding them there.

First thing to do is to make sure you've downloaded the right source for the gcc package. The place to find that is the GNU United States mirror page. You want to find the gcc-4.5.0.tar.bz2 or gcc-4.5.0.tar.gz file on the mirror site you choose. It will likely be in a gcc directory, and a gcc-4.5.0 sub-folder.

After you have that downloaded, you should untar it. In general you shouldn't build gcc in the folder you untar it into. So create another sibling folder that you actually want to build it in labeled gcc-build. Then the command you want is ../gcc-4.5.0/configure --prefix=$HOME/.local --enable-languages='c c++'.

gcc does require some other packages be installed in order to be able to compile itself. You can use the same --prefix line for these packages to install them in the same place. The gcc website has a list of pre-requisite packages.

$HOME/.local is sort of the standard accepted place for per-user installs of things.

Share:
43,167
Matthew Murdock
Author by

Matthew Murdock

Updated on February 23, 2020

Comments

  • Matthew Murdock
    Matthew Murdock over 4 years

    I have access to computer in a public library and I want to try out some C++ and maybe other code. Problem is that there is no g++ installed and I can't install it using packages because I have no root access. Is there a "smart" way to make a full environment for programming in a home folder?

    I have gcc installed (I can compile C code). Also, I have a home folder that is consistent. I don't know where to find precompiled g++, I found only source but I don't know what to do with it. I tried to ask them to install this but it didn't work :)

  • reece
    reece almost 14 years
    That is dependent on there being an existing compiler toolchain to bootstrap from.
  • Matthew Murdock
    Matthew Murdock almost 14 years
    I have gcc installed (I can compile C code). Also, I have a home folder that is consistent. I don't know where to find precompiled g++, I found only source but I don't know what to do with it. I tried to ask them to install this but it didn't work :)
  • Matthew Murdock
    Matthew Murdock almost 14 years
    I tried ./configure --prefix=... but it gives me: configure: error: cannot find install-sh, install.sh, or shtool in "." "./.." "./../.."
  • Omnifarious
    Omnifarious almost 14 years
    @user287655 - I will add this comment to your question so as to further clarify it.
  • Rudi
    Rudi almost 14 years
    It seems that you are trying to do the build inside the source tree. This is unsupported by the gcc maintainers, they want the build to be in a directory next to the gcc sources. Also, which packages did you unpack? You need both the gcc-core and gcc-g++ to generate the c++ compiler (or the complete[=largest] package). The missing install-sh is in the gcc-core package.
  • reece
    reece almost 14 years
    linuxfromscratch.org/lfs/view/stable may be useful for how-to get g++ building.
  • canesin
    canesin over 10 years
    I do recommend a stable release (like 2013.07) instead of the trunk, download from: ftp.gnu.org/gnu/gsrc
  • Alec Jacobson
    Alec Jacobson almost 10 years
    Will this also install a new version of standard lib c++?
  • Jerry Jeremiah
    Jerry Jeremiah over 7 years
    You actually need to do this before building GCC if you are using your own versions of GMP, MPC, MPFR and ISL because GCC uses those shared libraries.
  • Jerry Jeremiah
    Jerry Jeremiah over 7 years
    But don't try to build a new version of GCC. According to gcc.gnu.org/install/prerequisites.html GCC needs a C++98 compiler unless you are building GCC prior to 4.8 which allow bootstrapping with a C89 compiler