You can do it manually:
cd /usr/local/bin
sudo ln -s /usr/bin/gcc-10 gcc
sudo ln -s /usr/bin/g++-10 g++
Then open a new terminal windows and gcc should refers to gcc-10. It should work for simple cases. If it does not, you will have to create all the appropriate symbolic links for all GCC 10 ecutables and libraries...
I think the best option is to compile yourself GCC 10 and install it in your home directory. This is what I do on my minimalist Gentoo installation, I suppose it will work too on Ubuntu:
mkdir ~/src
cd ~/src
git clone https://github.com/gcc-mirror/gcc.git
mkdir gcc_build
cd gcc_build
../gcc/configure --enable-libsanitizer --prefix=~/usr --with-gcc-major-version-only --disable-bootstrap --enable-language=c,c++,lto
make -j16
make install -j16
Compilation may last about 10 minutes. Consider to adapt the -j16
option to your machine: this is the number of jobs launched simultaneously by make
. Using twice the number of parallel thread supported by your CPU is a good choice. Then add appropriate environment variables to your ~/.bashrc
file:
export LD_LIBRARY_PATH=~/usr/lib64:~/usr/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=~/usr/lib64:~/usr/lib:$LIBRARY_PATH
export LD_RUN_PATH=~/usr/lib64:~/usr/lib:$LD_RUN_PATH
export PATH=~/usr/bin:$PATH
When you do not want to use gcc-10 any more comment out these lines and open a new terminal.