Skip to content

Instantly share code, notes, and snippets.

@sirupsen
Forked from pengwynn/vim7.3_mac_install.rb
Created July 27, 2011 21:57
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save sirupsen/1110471 to your computer and use it in GitHub Desktop.
Save sirupsen/1110471 to your computer and use it in GitHub Desktop.
Script to install Vim 7.3 with ruby support for Mac OS X Lion
# requires root permissions in /usr/bin/
star = String.new
8.times { star += "*" }
Star = "\n#{star * 3}\n"
def newblock string
puts "\n#{Star}#{string}#{Star}\n"
end
newblock "compiling with system ruby"
system 'rvm system'
newblock " move to /tmp/"
Dir.chdir("/tmp\/")
pwd = Dir.pwd
newblock "curl & expand vim73 source"
system 'curl ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2 | tar -xz'
Dir.chdir"#{pwd}/vim73/"
newblock = "Start configure"
system "./configure"
newblock "Start options configuration"
# Will complain about xterm and clipboard - but they're enabled so...
system "./configure --with-features=huge --enable-cscope --enable-pythoninterp --enable-rubyinterp --enable-perlinterp --enable-gui=macvim --enable-multibyte --enable-clipboard=yes --enable-xterm_clipboard=yes"
newblock "Set arch in LDFlags"
arch = "-arch x86_64"
config = File.read("#{Dir.pwd}/src/auto/config.mk")
r = config.gsub(/.*LDFLAGS.*/,"LDFLAGS = -L. #{arch} -L/usr/local/lib")
File.open("#{Dir.pwd}/src/auto/config.mk", "w") { |file| file.puts r }
newblock "Make"
system "make"
newblock "new vim is in /tmp/vim73/src/vim. please verify by typing /tmp/vim73/src/vim --version\n
you may symlink it to /usr/bin if you'd like. 'sudo make install' will install to /usr/local/share/"
newblock "sudo Make"
system "sudo make install"
newblock "old vim symlink moved to /usr/bin/vim.old"
system "sudo mv /usr/bin/vim /usr/bin/vim.old"
system "sudo ln -s /usr/local/bin/vim /usr/bin/vim"
@gmassanek
Copy link

This was wildly helpful. Do you know how to specify which version of ruby you compile/install with if you're using RVM? If I do :ruby p RUBY_VERSION from within vim, it gives me 1.8.7 but I've set my default rvm version to 1.9.2 and I need vim to have the same. Any thoughts on how/where to adjust the above?

update - I was able to get around my problem. Just switched to 1.8.7 when I built command-t and that got around the final part. Thanks so much for this, very helpful.

@sirupsen
Copy link
Author

I did the same to get command-t to work, works fine. :-)

I got errors when I tried compiling Vim under RVM's Ruby 1.9.2, it seems to only compile with system Ruby.

@adrusi
Copy link

adrusi commented Aug 22, 2011

I installed this on lion. After running it (with root privileges via sudo) running $ vim gives me this error message:

dyld: Symbol not found: _environ
  Referenced from: /Users/Adrian/.rvm/rubies/ruby-1.9.2-p136/lib/libruby.1.9.1.dylib
  Expected in: flat namespace
 in /Users/Adrian/.rvm/rubies/ruby-1.9.2-p136/lib/libruby.1.9.1.dylib
Trace/BPT trap: 5

And the same for $ vim --version.

running $ vim.old still works, but it has no ruby support.

Also, I have rvm installed and my ruby version info is:

ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]

@adrusi
Copy link

adrusi commented Aug 22, 2011

Also, the vim executable does not exist inside /tmp/vim73/src/ although that directory exists.

@adrusi
Copy link

adrusi commented Aug 22, 2011

doing sudo make install in the /tmp/vim73/src/ directory failed after a while with this message:

ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [vim] Error 1

@sirupsen
Copy link
Author

vim should be build with system Ruby. Try running rvm system to switch to system ruby prior to running the script.

@adrusi
Copy link

adrusi commented Aug 22, 2011

Same errors.

Is there a particular directory where the script should be saved?

@adrusi
Copy link

adrusi commented Aug 22, 2011

also, since my second attempt, the backup in /usr/bin/vim.old has the same error.

@sirupsen
Copy link
Author

Shouldn't matter, it cd's itself accordingly.

@whistler
Copy link

whistler commented Sep 4, 2011

I get:

ld: library not found for -lruby.1.9.1
collect2: ld returned 1 exit status
make[1]: *** [vim] Error 1
make: *** [install] Error 2

@gkoberger
Copy link

Worked perfectly. Thanks!

@joeybeninghove
Copy link

+1 Worked great! Thanks!

@jpowell
Copy link

jpowell commented Oct 22, 2011

This worked for me on OS X Lion

Received ld errors initially which required installation of libiconv (http://www.gnu.org/software/libiconv/)

@neduma
Copy link

neduma commented Oct 26, 2011

thanks. works great.

@thefonso
Copy link

Not only does this not work for me, now, my old install of vim is not working. :(
My problem? ...I get this:

Undefined symbols for architecture x86_64:
"_iconv", referenced from:
_buf_write_bytes in fileio.o
_readfile in fileio.o
_my_iconv_open in mbyte.o
_string_convert_ext in mbyte.o
(maybe you meant: _my_iconv_open)
"_iconv_close", referenced from:
_buf_write in fileio.o
_readfile in fileio.o
_my_iconv_open in mbyte.o
_convert_setup_ext in mbyte.o
"_iconv_open", referenced from:
_my_iconv_open in mbyte.o
(maybe you meant: _my_iconv_open)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [vim] Error 1
make: *** [install] Error 2

@thefonso
Copy link

Great now Vim does not work also vim.old does not work.

@thefonso
Copy link

So instead of spending my night learning more about vim? I'm spending my night fixing a script. nice.

@jpowell
Copy link

jpowell commented Oct 31, 2011

@thefonso, did you try installing libiconv ? I commented on this above... there is nothing wrong with this script.

@thefonso
Copy link

thefonso commented Oct 31, 2011 via email

@tonyganch
Copy link

Worked fine for me without any additional installs (OS X Lion).
Thanks!

@daifu
Copy link

daifu commented Dec 19, 2011

I got this error:
ld: library not found for -lruby.1.9.1
collect2: ld returned 1 exit status
make[1]: *** [vim] Error 1
make: *** [install] Error 2

Is there any solution for that problem?

@fourcolors
Copy link

I'm getting that too.

Running. I ran rvm system

Ruby --version = ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]

I get this error

ld: library not found for -lruby.1.9.1
collect2: ld returned 1 exit status
make[1]: *** [vim] Error 1
make: *** [install] Error 2

@fourcolors
Copy link

Also I'm running OSX Lion

@daemonza
Copy link

Does not work for me on Lion, install libiconv, still does not work

UPDATE : I wanted to recompile vim to get command-t to work. In the end I did the following :
Install MacVim with homebrew
alias vim='mvim -v' in .bash_profile to get macvim to open like vim in a terminal.
cd ~/.vim/bundle/command-t/ruby/command-t
make clean
env ARCHFLAGS="-arch x86_64" ruby extconf.rb
env ARCHFLAGS="-arch x86_64" make

@AdrienGiboire
Copy link

This can't work. rvm system is unavailable as rvm is not loaded in current session as a function but remains as a binary. So rvm system do not switch to the good ruby version. I tried some things like:

newblock "Ensure that the right version of Ruby (1.8.7) is set"
if system('which rvm')
  if File.exists? ENV['HOME'] +"/.rvm/scripts/rvm"
    newblock "Load RVM into session *as a function*"
    `source "#{ENV['HOME'] +"/.rvm/scripts/rvm"}"`
  elsif File.exists?
    newblock "Load RVM into session *as a function* from a root install"
    `source "/usr/local/rvm/scripts/rvm"`
  else
    puts "ERROR: No RVM installation found.\n"
    exit
  end 

  `rvm use system`
end

But it doesn't work neither. I don't know what to do. Shell script?

@thefonso
Copy link

Laughing at my self on the post above. This script works like a charm on a virgin install of 10.7 Lion. Shout out to my Code-brother, you know who you are.

@nschwermann
Copy link

Spit out Error 1 and Error 2 towards the end but seemed to work overall...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment