Setting up an environment for a Binary snapshot of gcc
Andrew C Aitchison
ubuntu at aitchison.me.uk
Thu Jan 22 17:17:13 UTC 2026
On Thu, 22 Jan 2026, Ian Bruntlett wrote:
> Hi,
>
> I have 2 questions about Ubuntu system administration:
>
> *The situation.*
> Using Ubuntu 24.04.3 x86_64 LTS
> I installed gcc-latest_16.0.0-20260111git8e4107a1b3d4.deb
> $ sudo dpkg --install gcc-latest_16.0.0-20260111git8e4107a1b3d4.deb
> The .deb file came from https://jwakely.github.io/pkg-gcc-latest/
>
> This prerelease of gcc runs from /opt/gcc-latest/bin so, to get that onto
> the PATH, I put these 2 lines at the bottom of .bashrc:
> # Things for running gcc-latest
> PATH=/opt/gcc-latest/bin:$PATH
>
> *Question 1.*
> Is that sensible? With a bit more work I got g++ to compile a simple Hello
> World programme - I needed to sudo apt install binutils first.
>
> So that Hello World could find the standard C++ library, I had to source a
> shell script which did this:
> #!/bin/bash
> echo $PATH
> set -x
> export LD_LIBRARY_PATH=/opt/gcc-latest/lib64
>
> *Question 2.*
> Is that sensible? Should I put it in .bashrc as well?
.bashrc is one way to do it, but I suggest that you
explore the "environment-modules" package.
For a differently packaged/installed version of gcc 16 I have
this module file:
#%Module########################################
## conflict gcc
conflict llvm
set gnu_basedir /usr/lib/gcc-snapshot
set GNU_BIN $gnu_basedir/bin
setenv CC gcc-snapshot
setenv CXX g++-snapshot
setenv GNU_PATH $GNU_BIN
prepend-path PATH $gnu_basedir/bin
prepend-path CPATH $gnu_basedir/include/c++
setenv LD_SHARED "g++ -shared"
# For clang/llvm scan-build analyzer
setenv CCC_CC $GNU_BIN/gcc
setenv CCC_CC $GNU_BIN/g++
setenv COMPILER gcc
setenv CMAKE_C_COMPILER $GNU_BIN/gcc
setenv CMAKE_CXX_COMPILER $GNU_BIN/g++
proc ModulesHelp { } {
puts stderr "\t makes gcc, g++ and friends use gnu snapshot (16)"
puts stderr ""
}
--------------------------
This way I keep all the settings for gcc-16 together,
and can switch from the system compiler with:
module load gcc/_standalone
and back with
module unload gcc
(There is also a command "ml" in package module-assistant which
allows an even shorter syntax for loading and unloading modules.)
You may notice the reference to an llvm module
- that alloww me to switch compiler to clang/clang++ to check my code against
a second compiler ...
I dont appear to be changing LD_LIBRARY_PATH or LIBRARY_PATH
- iirc the right way to do that is with -rpath=... and similar linker options
(use -Wl,option when setting from the compiler options)
but you can set them with setenv, prepend-path and append-path, eg
append-path LIBRARY_PATH /usr/lib/x86_64-linux-gnu:/lib/x86_64-linux-gnu
--
Andrew C. Aitchison Kendal, UK
andrew at aitchison.me.uk
More information about the ubuntu-users
mailing list