mac 电脑升级后 出现sass 无法编译,然后我安装sass出现一下错误,网上找了很多方法都不能解决
sudo gem install sass
Building native extensions. This could take a while...
ERROR: Error installing sass:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20230226-19112-3yzmby.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
--with-ffi_c-dir
--without-ffi_c-dir
--with-ffi_c-include
--without-ffi_c-include=${ffi_c-dir}/include
--with-ffi_c-lib
--without-ffi_c-lib=${ffi_c-dir}/lib
--enable-system-libffi
--disable-system-libffi
--with-libffi-config
--without-libffi-config
--with-pkg-config
--without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
from extconf.rb:9:in `system_libffi_usable?'
from extconf.rb:42:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.5/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.5/gem_make.out
--------------------
分割线
这是我 查看版本报的错
sass -v
-bash: /usr/local/bin/sass: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: bad interpreter: No such file or directory
我想试试安装最新的ruby
brew install ruby
==> Downloading https://formulae.brew.sh/api/formula.json
##O#-#
==> Downloading https://formulae.brew.sh/api/cask.json
######################################################################## 100.0%
Warning: ruby 3.2.1 is already installed and up-to-date.
To reinstall 3.2.1, run:
brew reinstall ruby
但是查看版本确实2.6不知道是不是这个问题导致sass无法安装
ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin21]
请到老们看看
Then I solved
虽然ruby安装到最新版本,但ruby-v后版本仍然是老版本
ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin21]
这时需把 ruby 最新可执行文件导入全局变量 PATH 中即可,使用如下命令:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
再ruby-v
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [x86_64-darwin18]
安装sass
gem install sass
提示
Successfully installed sass-3.7.4
但是我sass -v
-bash: /usr/local/bin/sass: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: bad interpreter: No such file or directory
在安装完sass后有提示我升级gem
Run `gem update --system 3.4.7` to update your installation
我就升级gem
gem update --system
sass -v 就可以显示版本号了
0 Answer
the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > this error message when installing the gem is compiled native extensions error caused by, This may be due to a lack of necessary libraries or header files. According to the error message, you will need to install the development tools before compiling native extensions. You can try to install the development tool by running the following command:
xcode-select --install
If you have installed the Xcode development tool and are still experiencing this problem, you can try updating the Xcode development tool or run the following command to update the Xcode development tool path:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
If you have updated the Xcode development tool and are still experiencing problems, check the mkmf.log file for more detailed error information. You can open mkmf.log by running the following command:
less /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.5/mkmf.log
When viewing the mkmf.log file, you can search for keywords such as error, warning, and fatal to determine the cause of the compilation error. If you still can't fix the problem, try using a tool like RVM or rbenv to install Ruby to avoid affecting your system environment.
这家伙很懒,什么都没留下...