SCL (software collection) is a very handy tool to control gcc version in CentOS.

Unfortunately, there currently no equivalent in Ubuntu.

sudo yum install centos-release-scl
sudo yum install devtoolset-9
scl enable devtoolset-9 bash