Having trouble installing ruby gem for iStats

2

I am trying to install iStats via a ruby gem.

First I ran the command:

xcode-select --install and the output was:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates. So that was okay.

Then I ran:

sudo gem install iStats

and the output was:

Building native extensions.  This could take a while...
ERROR:  Error installing iStats:
ERROR: Failed to build gem native extension.

current directory: /Library/Ruby/Gems/2.3.0/gems/iStats-1.6.1/ext/osx_stats
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20190117-44665-taivle.rb extconf.rb
creating Makefile

current directory: /Library/Ruby/Gems/2.3.0/gems/iStats-1.6.1/ext/osx_stats
make "DESTDIR=" clean

current directory: /Library/Ruby/Gems/2.3.0/gems/iStats-1.6.1/ext/osx_stats
make "DESTDIR="
make: *** No rule to make target `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin16/ruby/config.h', needed by `smc.o'.  Stop.

make failed, exit code 2

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/iStats-1.6.1 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-16/2.3.0/iStats-1.6.1/gem_make.out

I'm not sure what all of this means, but I know it did not work. So I tried installing ruby using:

brew install ruby, which seemed to do its job.

Then I tried the sudo gem command again but I got the same output as above.

What is going wrong here?

EDIT:

I just read https://stackoverflow.com/a/26600110/6678549 and tried this:

sudo gem update --system and got this output:

Updating rubygems-update
Successfully installed rubygems-update-3.0.2
Parsing documentation for rubygems-update-3.0.2
Installing darkfish documentation for rubygems-update-3.0.2
Done installing documentation for rubygems-update after 108 seconds
Parsing documentation for rubygems-update-3.0.2
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 3.0.2
ERROR:  While executing gem ... (Errno::EPERM)
Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem

So it almost worked, but I'm still no closer to installing iStats.

EDIT 2:

My ruby version is ruby 2.3.7p456 in case it is relevant and I am using MacOS Sierra. I have done a bit of reading and found about System Integrity Protection. I have tried a few other commands like sudo gem install iStats -n /usr/local/bin, but still nothing works. Although after runningsudo gem update --system` it now says the latest version is already installed.

AkThao

Posted 2019-01-17T14:18:16.530

Reputation: 43

Answers

0

I have done it!

I am not sure exactly what I did right, but I used these two commands:

export LDFLAGS="-L/usr/local/opt/ruby/lib"

export CPPFLAGS="-I/usr/local/opt/ruby/include"

Then I tried:

sudo gem install iStats

and

sudo gem install iStats -n /usr/local/bin

Now I have successfully installed iStats 1.6.1.

Strangely though, I used those two export commands earlier on and they did not do the trick. So something must have changed in the meantime, I don't know what it is.

AkThao

Posted 2019-01-17T14:18:16.530

Reputation: 43

1

Note that I recommend against messing with the system Ruby and instead installing rbenv: https://github.com/rbenv/rbenv – this should make your life easier, and you don't need to run sudo for anything.

– slhck – 2019-01-17T15:52:26.983

@slhck Thanks for the advice, I'll keep that in mind in the future. – AkThao – 2019-01-17T18:56:10.570