NoMethodError with Ruby when installing SoundCloud 2000 client for CLI

1

I’m trying to install SoundCloud2000 on my MacBook running Mac OS X 10.8.5.

I have Ruby 2.2.0, mpg123, and portaudio installed. Installing SoundCloud 2000 as a GEM seems to work fine:

gem install soundcloud2000

But then when I try to use it from the command line when I run—$soundcloud2000—I get the following error instead of the client:

/Library/Ruby/Gems/1.8/gems/soundcloud2000-0.1.0/lib/soundcloud2000.rb:1: undefined method `require_relative' for main:Object (NoMethodError)
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /Library/Ruby/Gems/1.8/gems/soundcloud2000-0.1.0/bin/soundcloud2000:3
    from /usr/bin/soundcloud2000:19:in `load'
    from /usr/bin/soundcloud2000:19

I don’t know what this means. Anyone else know?

Alison

Posted 2014-12-31T16:00:24.080

Reputation: 23

Answers

0

You say you have Ruby 2.2.0 installed, but looking at the error all of the references are for /Library/Ruby/Gems/1.8/gems/ which means SoundCloud 2000 is installed as a Ruby 1.8 GEM. So my guess is however you installed Ruby 2.2.0 that is not the main ruby you are running from the command line. You can confirm with version of Ruby you are running on your Mac by running this command:

ruby -v

The output should be something like this; note on I am running Mac OS X 10.9.5 so my installed version of Ruby will be higher than Mac OS X 10.8.5:

ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin13]

You can also see where your version of Ruby is being loaded from via which like this:

which ruby

The output should be something like this:

/usr/bin/ruby

The which tool tells you exactly what path the binary you are calling via that command is being loaded from.

Since it seems like you are using Homebrew to install a newer version of Rub, you need to also make sure your user’s $PATH is set to check /usr/local/bin before checking /usr/bin. This is typically set in the .bash_profile file in your home directory which is located via ~/.bash_profile. Just note that this stuff might also be set in a file named .bashc, so adjust the examples to use .bashc instead of .bash_profile if that is the case.

For example, if I run the following command on my Mac OS X setup:

cat ~/.bash_profile

I see these contents:

export PATH="/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/opt/ImageMagick/bin"

Might look complex, but it isn’t. All that command does is basically set the $PATH settings for your shell environment. And the items between the quotes are just directory paths separated by : characters. Of note to you this the order of /usr/bin versus /usr/local/bin; one comes in front of the other. Which basically means the system will check for ruby in /usr/bin and prefer to use that one before it even reaches the ruby installed via /usr/local/bin. So a quick fix for you would be to take /usr/local/bin and place it in front of /usr/bin via a text editor like nano. Then save it, exit your Terminal session and open a new one.

That said, if I were you I would recommend avoiding system level Ruby and Ruby GEM installs via Homebrew and rather use RVM (Ruby Version Manager) instead. Ruby—and Ruby GEMs—can actually be a pain to deal with on a good day; and even a worse of a headache on a Mac. So using RVM instead can allow you to create isolated Ruby and Ruby GEM installs specific to your user that are easier to manage.

I do Linux systems administration and tend to want to upgrade the version of Ruby installed by default and used to do that via source or package installers. But the more work I do on Ruby setups, the more I’ve realized that RVM is really the best way to install, manage and deal with Ruby setups. Slight learning/understanding curve when you first set it up but past that it will make your life—and system management—tons easier.

JakeGould

Posted 2014-12-31T16:00:24.080

Reputation: 38 217

1You're right @jakegould, that says I'm using ruby 1.8.7. I'm trying to install the newer version now with brew install ruby – Alison – 2014-12-31T17:12:29.910

@Alison Bingo! Check my latest edit where I explain how to can fix this by adjusting your $PATH on the system. And I also recommend avoiding Homebrew for Ruby stuff like this and instead use RVM (Ruby Version Manager). – JakeGould – 2014-12-31T17:44:53.973

@Alison I am sorry you are running into these issues, but posting error messages like this in comments is bad. Not readable and hard to manage. It is better if you amend your question to post your new challenges and issues you face in installing SoundCloud 2000. – JakeGould – 2014-12-31T18:34:44.010

oh okay sorry about that, will do @jakegould – Alison – 2014-12-31T18:36:13.507

Also, if you are now using Ruby 2.2.0 you would have to reinstall mpg123 and portaudio so they will use Ruby 2.2.0 instead of 1.8.7. Also, please check this error discussion in the official SoundCloud2000 repo. https://github.com/grobie/soundcloud2000/issues/69

– JakeGould – 2014-12-31T18:37:13.230

ahhh, excellent, that's the exact problem I'm having. Thank you so much for your help @jakegould, it is invaluable!! – Alison – 2014-12-31T18:39:29.313

@Alison You are welcome! Happy to have helped. If my answer was helpful to you, please remember to upvote it. And if this is the answer that solved your issue, please be sure to check it off as such when you can. – JakeGould – 2014-12-31T19:01:40.583

1thanks @jakegould, I cannot upvote it because I have not been on stackexchange long enough/don't have the reputation to upvote, but I did check it off. thank you again for all your help! – Alison – 2015-01-02T20:55:38.283