MacVim cannot find gems when launched from the command line - ruby

I have MacVim installed with Janus and a few extra lines in both .vimrc.local and .gvimrc.local.
When I launch mvim from the terminal (iterm2 or terminal) and try !rails -v I get
Could not find RubyGem rails (>= 0) (Gem::LoadError)
Launching MacVim from the dock and doing !rails -v works fine and returns Rails 3.0.7.
I get the same behaviour with all gems.
I realise I'll likely have to provide more information to solve this but tbh I have no idea whether it is macvim, rvm, bash, or something else causing the issue.
TIA

I also use MacVim (I'm running it from iTerm (screen)), and !rails -v works.
Did you set rvm installed ruby interpreter to be default ruby executable on system? Try running
which ruby
from terminal, and also you could try to run !which ruby from MacVim. You should get something like:
/Users/your_user/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
If not, try setting one of your rvm installed rubies as default (As explained on http://beginrescueend.com/rubies/default/).

Related

Can't start ruby from osx yosemite terminal, before and after rbenv, homebrew works though

Every time I type ruby and hit Enter at my terminal, it just hangs for seemingly forever. This is happening for the default Yosemite install and after I installed with rbenv, using Homebrew (which works fine), using "Ruby on Rails development setup for Mac OSX".
My current Ruby version is 2.2.2, ruby -v works, and I didn't have this problem when I was using OS X Mavericks.
Has anyone else had this problem and/or found a solution? My google-fu doesn't seem to be strong enough.
When you enter ruby at the command-line, it's supposed to "hang forever". It's waiting for you to give it instructions. You can use CTRL+D to get it to stop waiting:
> ruby
puts 1 + 1
2
I then did CTRL+D and returned to the command-line prompt.
Instead though, we don't use Ruby like that. If we want to use it interactively, we use IRb which comes with Ruby. It's the "interactive" Ruby:
> irb
Welcome to IRB. You are using ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin13]. Have fun ;)
>> 1 + 1
2
>> 'foo'.squeeze('o')
"fo"
If we want to run a Ruby script, we use something like:
ruby /path/to/script
and Ruby will load and run it.
I'd recommend reading some Ruby tutorials and learn how the language works before trying to use Rails. Rails uses deep Ruby magic and how Rails works will be unfathomable to you until you do understand better how Ruby is used and how it works and what it can do.
If you're using rbenv to manage your Ruby, then when you enter rbenv versions you should see the Rubies it manages listed:
rbenv versions
system
1.9.3-p551
* 2.2.2 (set by /Users/tinman/.rbenv/version)
If you don't, either rbenv isn't in control of Ruby, or you haven't installed any using rbenv. rbenv global system will tell it to use whatever you have installed by default in the system, based on your PATH.
rbenv's documentation and built-in help go over this so if the problems continue then you need to closely examine your install and setup, because 90% of the problems we see using a sandboxed Ruby are due to people not paying attention to the directions, or using the wrong ones, and not completing the installation.

What tool runs during a "cd" and checks the .ruby_version file?

I've installed a bunch of tools related to ruby recently. Macports ruby19 (then uninstalled per advice here on SO), then installed RVM and ruby-1.9.3-p.
Now I notice that I get a message when I cd or even \cd into a directory with a .ruby-version file that I do not have the matching version of ruby installed. And it's driving me crazy: what tool is performing this check?
The only thing that I can see that rvm did to my environment is to append ~/.rvm/bin onto my path. I'm running "terminal" on OS X Mountain Lion.
edit: is there some way to tell bash to echo all processes launched from a shell command?
The cd is overwritten by RVM.
.ruby-version is a "standard" used by RVM/rbenv/chruby to allow you to switch to project specific Ruby.
You can fix this problem in two ways:
Make RVM install all missing rubies:
echo rvm_install_on_use_flag=1 >> ~/.rvmrc
Make RVM install Ruby for current project:
rvm use . --install

irb not starting

I'm running Ruby 1.9.2 w/ rbenv. I recently moved my Users directory to a different drive. Ruby and irb show up using which.
$ which ruby
/Volumes/Pig/Users/arrow/.rbenv/shims/ruby
$ which irb
/Volumes/Pig/Users/arrow/.rbenv/shims/irb
However, running irb hangs indefinitely.
I've also been running ruby files under the current config but executing $ ruby -v also hangs.
rbenv rehash can help solve these sort of problems. Anytime you modify your Ruby installation you need to rerun that command to let rbenv rebuilt its soft-links.
From the command-line output:
rehash Rehash rbenv shims (run this after installing binaries)
You might also need to tell rbenv where your binaries are again, i.e., rbenv global 1.9.2... and let it adjust things.
Remember, rbenv assumed your binaries were on a different volume so it might have gotten confused and needed you to straighten it out.
The other issue could be that Ruby bound to files on the other volume at compile time (because that's what rbenv does, it compiles Ruby for you) so when the files couldn't be found the apps crashed. Reinstalling rbenv would fix that, as telling it to reinstall a particular Ruby should have fixed it.
I uninstalled/installed rbenv and all is well.

Can't enter Umlauts in Ruby 1.9.3 IRB

I am experiencing very strange behavior in Ruby 1.9.3's IRB with Mac OS 10.7.3
When I try to enter an Umlaut, it's escaped in the prompt and looks like this (I entered "ΓΌ" on the keyboard)
irb(main):001:0> "\U+FFC3\U+FFBC"
What's super strange is this:
irb(main):001:0> "\U+FFC3\U+FFBC".length
=> 0
Of course, the character isn't displayed either:
irb(main):001:0> "\U+FFC3\U+FFBC"
=> ""
Does anyone know what's going on here or how to fix this?
Victor Moroz didn't quite give the definitive answer but his link led me to a solution (thx!):
I forgot to mention:
Im running homebrew
I built ruby using ruby-build and this recipe (1.9.3-p125-perf, with falcon patches)
What I then did to solve this problem in my case was to recompile, this time pointing ruby to a more recent version of readline (6.2.2 in my case) that I installed with homebrew.
The steps it took were:
$ brew install readline
$ export CPPFLAGS=-I/usr/local/Cellar/readline/6.2.2/include
$ export LDFLAGS=-L/usr/local/Cellar/readline/6.2.2/lib/
$ curl https://raw.github.com/gist/1688857/rbenv.sh | sh && rbenv global 1.9.3-p125-perf
I ran across this problem as well, but my Ruby was built with rvm rather than ruby-build. I'd also previously used Homebrew on Mountain Lion to run other package installers, and among them got Readline 6.2.5 or something like that. This turns out to be the cause of this issue for me. So here's the fix:
From the RVM site:
If you have an error when compiling pertaining to readline, you may need to attempt installing with the procedure defined below.
$ rvm pkg install readline
$ rvm reinstall 1.9.2 --with-readline-dir=$rvm_path/usr
Note that this error occurs most often when having a MacPorts, Fink, or Homebrew installed readline on your system.
Hope this helps someone else!
This may help http://henrik.nyh.se/2008/03/irb-readline
UPDATE In fact on my Mac I have no problem with port version of Ruby, but original Mac OS version does have this problem (never used that one). So the easiest way is probably just to install Ruby from ports.
this command solved it for me:
brew install readline
RUBY_CONFIGURE_OPTS=--with-readline-dir="$(brew --prefix readline)" rbenv install 1.9.3-p286
source: https://github.com/rbenv/ruby-build/wiki

Can RVM find versions of ruby it did not install?

I'm running os x lion. A version of ruby was installed when I installed the OS. I then installed RVM and then installed ruby 1.9.2 and made it the default for new shells.
Default Ruby (for new shells)
ruby-1.9.2-p290 [ x86_64 ]
What happend to the older version of Ruby that was already on my system and how can I remove it since RVM doesn't see it?
When I try to use the new hash syntax in code written in textmate or sublime text 2 it fails. When the same code is run in the shell it works. So how do I make ruby 1.9.2 the only ruby installed on my system?
You do NOT want to uninstall the system Ruby. It is required for a lot of applications (including RVM) to function properly.
If you want applications like Textmate or Sublime Text to use a different version of Ruby, you can update their individual configuration settings to set the path to the Ruby binary you wish to use.
Since those apps don't run ruby from the shell like you do they don't work seamlessly with RVM. Fortunately RVM's web site has instructions on integrating RVM with TextMate. You shouldn't have trouble applying the same process for Sublime Text 2 but if you do the web does not want for tutorials on the topic.
Also, RVM is not responsible for any ruby it didn't install. the only other ruby it gives access to is the system ruby, and there it doesn't do gemsets etc. (This is also due to systems like debian that specifically block off things like gem update --system so you don't poison the package that was installed. RVM protects from that as well)

Resources