Linux环境下安装R语言xgboost包报错:升级gcc后仍提示版本不足求助
Hey there! I’ve run into this exact snag before—upgrading GCC doesn’t automatically mean your system or R is using the matching G++ version. Let’s walk through the steps to get this sorted out:
Step 1: Check Your Current G++ Version
First, confirm if G++ was upgraded alongside GCC. Run this in your terminal:
g++ --version
If it still shows 4.4.7, you only updated GCC, not G++. Fix this based on your Linux distro:
- CentOS/RHEL: Use the Software Collections (SCL) repo to install G++ 4.9:
Then activate the updated compiler environment:sudo yum install centos-release-scl sudo yum install devtoolset-3-gcc-c++source /opt/rh/devtoolset-3/enable - Debian/Ubuntu: Install G++ 4.9 directly:
sudo apt-get update sudo apt-get install g++-4.9
Step 2: Tell R to Use the Updated G++
If G++ is now 4.9.2 but R still throws the error, you need to explicitly point R to the new compiler. Open R and run these commands:
# Set the default C++ compiler Sys.setenv(CXX = "/usr/bin/g++-4.9") # Specify C++11 compiler (xgboost requires this) Sys.setenv(CXX11 = "/usr/bin/g++-4.9") # Now try installing xgboost again install.packages("xgboost")
If you’re installing from the GitHub source, use:
devtools::install_github("dmlc/xgboost", subdir = "R-package")
Step 3: Set Updated G++ as System Default (Optional)
If you want G++ 4.9 to be the system-wide default, update the symbolic links:
- Find the path to G++ 4.9:
which g++-4.9 - Backup the old G++ link:
sudo mv /usr/bin/g++ /usr/bin/g++-old - Create a new link to G++ 4.9:
sudo ln -s /usr/bin/g++-4.9 /usr/bin/g++
Verify the change with g++ --version—it should now show 4.9.2.
Quick Tip
If you’re compiling xgboost from scratch outside R, make sure you’ve activated the updated compiler environment first (e.g., source /opt/rh/devtoolset-3/enable for CentOS) before running make or cmake.
内容的提问来源于stack exchange,提问作者sm925

