You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux环境下安装R语言xgboost包报错:升级gcc后仍提示版本不足求助

Fixing XGBoost Installation Error: g++ Version Mismatch After GCC Upgrade

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:
    sudo yum install centos-release-scl
    sudo yum install devtoolset-3-gcc-c++
    
    Then activate the updated compiler environment:
    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:

  1. Find the path to G++ 4.9:
    which g++-4.9
    
  2. Backup the old G++ link:
    sudo mv /usr/bin/g++ /usr/bin/g++-old
    
  3. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:53:26