服务器仅支持GCC 4.3.2,安装Rails时sassc编译失败求助
Hey there, let's work through this problem step by step—since your server is stuck on GCC 4.3.2 and can't upgrade, the -flto error pops up because that link-time optimization flag was added in GCC 4.6, which your older version doesn't support. Here's how to address each of your questions:
1. Quick Fix for the Compilation Error
The simplest workaround is to disable the unsupported -flto flag during gem installation. Set these environment variables before running bundle install to override the compiler settings:
CFLAGS="-fno-lto" CXXFLAGS="-fno-lto" bundle install
This tells the compiler to skip link-time optimization, letting sassc compile successfully without needing a GCC upgrade.
Another option is to install an older sassc version that doesn't use the -flto flag. Versions before 2.0 (like 1.12.1) avoid this optimization. Force this version by adding it to your Gemfile:
gem 'sassc', '1.12.1'
Then run bundle update sassc to install the compatible older build.
2. Can You Exclude sassc Installation?
Yes, since you didn't add it to your Gemfile, it's a transitive dependency (most likely from sass-rails or another asset-related gem). Here are two reliable ways to skip installing it:
- Switch to pure-Ruby Sass: Replace sassc with the original Ruby implementation of Sass, which requires no native compilation. Add these lines to your Gemfile:
Rungem 'sass-rails', '~> 5.0' # Match your Rails version; 5.x supports Ruby Sass gem 'sass', '~> 3.7' # Pure-Ruby Sass, no native extensions neededbundle update sass-railsto switch the dependency away from sassc. - Use Bundler to override the dependency: If you need to keep your current
sass-railsversion, tell Bundler to skip sassc entirely by adding:
This blocks sassc installation for all platforms. Just note: test your app thoroughly afterward, as some gems might rely on sassc-specific functionality.gem 'sassc', platforms: []
3. Can You Delete sassc from the .gems Folder?
Absolutely, but this is only a temporary fix—Bundler will try to reinstall sassc the next time you run bundle install unless you fix the dependency root cause. To remove it:
- Locate the sassc directory in your
.gemsfolder (e.g.,~/.gems/gems/sassc-2.2.1) - Delete the directory entirely
- Optionally, clean up cached gem files with:
gem cleanup sassc
Remember: this won't stop future reinstalls unless you adjust your Gemfile or dependency overrides as outlined in question 2.
内容的提问来源于stack exchange,提问作者pvdhpl

