0%

Install GCC without root permission

Problem description

Sometime, we want to relative new version of basic building tools on a linux sever, where we don’t have root permission, to install some software not so popular to our own account.

For my case, I want to install MOAB, PyNE and DAGMC on a sever maintained by the several PhD or post-doctor researchers. This sever is used for some specific purpose highly related to the research. There isn’t a staff versatile enough to cope with the sever maintaince. There isn’t a moudle on the sever. Some characters of the sever:

  • No tool module
  • Some prebuild tools, such as GCC, are old version
  • I don’t have root permission

While, maybe the better way to solve the problem is to ask experts to do install anything you want for me. But, I can’t find out a person with enough knowledge in our research group to do that. So, I am going to build a GCC on my own without root permission.

Setup GSRC

I way I choose to install GCC is use GSRC (GNU Source Release Collection) to install it.
Note: Do not download GSRC package from ftp, use bzr to download it.

1
2
3
4
5
6
7
8
9
10
11
bzr checkout bzr://bzr.savannah.gnu.org/gsrc/trunk/ gsrc
# (use "bzr checkout --lightweight" to download the latest revision only)
# there isn't a bzr on the sever, so I download the file from https://ftp.gnu.org/gnu/gsrc/ and scp the file to the server and then extract

cd gsrc/
./bootstrap # to create the configure script
./configure --prefix=$HOME/opt/GNU # --prefix is directory to install the packages
# Pick your --prefix by your wishes.
. ./setup.sh # This just sets some ENV variables and appends to PATH
# and other variables to allow GSRC to work seamlessly.
# Put this line in your .bashrc.

Set GSRC environment

Open ~/.bashrc, add the following line in the file:

1
source $PATH_TO_GSRC/setup.sh

Install dependencies

Update ISL

ISL is a required by GCC, but the version of the prebuild one is too lower thant 0.15. So, install ISL.

1
2
make -C pkg/other/isl
make -C pkg/other/isl install

Install GCC

Now, I want to install GCC-7.4.0 on the sever.

Modify config.mk

Before install GCC, there are some configure options should be changed. Open the gsrc/pkg/gnu/gcc7/config.mk, edit the following items:

  • --enable-languages=c,c++,fortran
  • --disable-multilib

make

Run the following commands:

1
2
# cd PATH_TO_GSRC
make -C pkg/gnu/gcc7

Catch problems and fix

When you running perform make, there may be some error like this:

  1. ...suspect...32...multilib..., if 64... rerun with --disable-multilib. Just RERUN the same make process.
  2. ...vec.h:295:7: error: ‘GATHER_STATISTICS’ was not declared in this scope.
    Form here I know the solution is unset a bunch of C compiler flags:
    1
    unset LIBRARY_PATH CPATH C_INCLUDE_PATH PKG_CONFIG_PATH CPLUS_INCLUDE_PATH INCLUDE
    And run the make again:
    1
    make -C pkg/gnu/gcc7

make install

1
2
make -C pkg/gnu/gcc7 check
make -C pkg/gnu/gcc7 install

Post-install, env set

The GCC binaries I installed have the suffix of -7. Link them to the name without -7. Acutally, I can modify the pkg/gnu/gcc7/config.mk and change the --program-suffix to none to avoid this suffix.

1
2
3
4
cd $HOME/opt/GNU/bin
ln -sf gcc-7 gcc
ln -sf g++-7 g++
ln -sf gfortran-7 gfortran

Done!