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

升级GCC至6.4后R Studio中GCC路径未更新的解决求助

Fix GCC Version Mismatch in RStudio After System Upgrade

It looks like the core issue here is that RStudio isn't picking up the updated GCC path from your system environment—even though your terminal uses GCC 6.4.0, RStudio is still clinging to the old 4.6.2 version because it inherits a different set of environment variables. The Sys.setenv(PKG_CXXFLAGS="-std=c++11") command you tried only sets a compiler flag, not the actual path to the new GCC executable, so it couldn’t fix the root problem.

Here are actionable steps to get RStudio using your upgraded GCC 6.4.0:

1. First, Confirm RStudio’s Current Environment

Run these commands in the RStudio console to see what’s going on under the hood:

# Check the order of directories in your PATH
cat(Sys.getenv("PATH"), "\n")

# See which compilers RStudio is currently pointing to
Sys.getenv(c("CC", "CXX"))

You’ll probably notice that /usr/local/gcc-6.4.0/bin isn’t in the PATH, or that CC/CXX are still pointing to the old /usr/bin/gcc/g++.

2. Temporary Fix (Session-Only)

If you just need the new GCC for your current RStudio session, set the environment variables directly in the console:

# Prepend the new GCC bin directory to PATH so it gets prioritized
Sys.setenv(PATH = paste("/usr/local/gcc-6.4.0/bin", Sys.getenv("PATH"), sep = ":"))

# Explicitly tell R to use the new compiler binaries
Sys.setenv(CC = "/usr/local/gcc-6.4.0/bin/gcc")
Sys.setenv(CXX = "/usr/local/gcc-6.4.0/bin/g++")

Test it right away to confirm:

system2("gcc", "--version")

You should now see GCC 6.4.0 in the output. Note this change resets when you close RStudio.

3. Permanent Fix (Persists Across Sessions)

To make this stick for every RStudio launch, edit your R environment file (~/.Renviron):

  1. Open the file directly from RStudio:
    file.edit("~/.Renviron")
    
  2. Add these lines to the file:
    PATH="/usr/local/gcc-6.4.0/bin:$PATH"
    CC="/usr/local/gcc-6.4.0/bin/gcc"
    CXX="/usr/local/gcc-6.4.0/bin/g++"
    
  3. Save the file and restart RStudio. The new compiler will load automatically from now on.

4. Fix for Desktop Shortcut Launches

If you launch RStudio from a desktop shortcut (not the terminal), it might skip loading your terminal’s environment variables (like those set in ~/.bashrc or ~/.profile). To fix this:

  • Find your RStudio desktop file (usually at /usr/share/applications/rstudio.desktop or ~/.local/share/applications/rstudio.desktop).
  • Edit the Exec line to prepend the environment variables:
    Exec=env PATH="/usr/local/gcc-6.4.0/bin:$PATH" CC="/usr/local/gcc-6.4.0/bin/gcc" CXX="/usr/local/gcc-6.4.0/bin/g++" rstudio %F
    
  • Save the file, log out and back in, then launch RStudio again.

Quick Note on Your Original Command

Sys.setenv(PKG_CXXFLAGS="-std=c++11") only tells R’s package compiler to use C++11 standards—it doesn’t change which GCC executable is being used. You need to point RStudio to the new binary path first, then set any compiler flags you need.

内容的提问来源于stack exchange,提问作者kiris

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:59:21