First of all, don’t. Just use the system ruby.
Here’s my experience so far. Note, I had set aside a full day on Feb 16th for this job. I had nothing else to do that day other than this install. However, I started ahead of time on Feb 15th.
Please note, towards the end of day 3 so much had gone wrong I was struggling to keep track of the various threads. I.e. whether a certain process was correct or incorrect and likely to lead to a successful install of that particular piece of software.
Also, the #rvm channel on Freenode was pretty much useless. Very rarely got a useful response.
[NB: shortcut - go down to the very end of this post for the latest.]
15 Feb 2012
Helpful links:
http://www.ruby-lang.org/en/documentation/quickstart/3/
http://www.rubyinside.com/advent2006/10-gserver.html
Install JSON via:
sudo gem install json
Tutorial on hashes:
http://www.troubleshooters.com/codecorn/ruby/basictutorial.htm#_Hashes
Guide to JSON implementation for Ruby:
http://flori.github.com/json/doc/index.html
Deploying an app to Dreamhost:
1. Create a subdomain specially for this RoR app
2. Enable Passenger
3. Create a test config.ru above public/
E.g.
app = proc do |env|
[200, { “Content-Type” => “text/html” }, [“hello <b>world</b>”]]
end
run app
4. Create a tmp/restart.txt file (above public/). This notifies Rails when you’ve made changes and a restart is required.
5. And came to a full stop here as RoR would not work other than the “hello world” script!
Attempt 2 at deploying a Ruby app: Deploying to Google App Engine using JRuby:
http://code.google.com/p/appengine-jruby/wiki/GettingStarted
Very easy instructions. Worked perfectly.
Experience:
- immensely slow initially! (like 20 seconds. now better, around 5 seconds).
- also, other people have seemed to struggle: https://groups.google.com/forum/?fromgroups#!topic/appengine-jruby/185J8uKFDOk
Deploying on Heroku:
http://devcenter.heroku.com/articles/ruby
Installed perfectly.
Notes when making changes.
Adding:
require ‘json’
did not work when starting foreman.
Needed to add the gem to the Gemfile.
Then, interestingly, when I did a push to Heroku I got:
“Installing json (1.6.5) with native extensions”.
So far, so good.
16 Feb 2012
Install Rails locally:
See Rails installation screencast here: http://ruby.railstutorial.org/
Note, added this useful bit of bashrc magic:
PS1=’[\W$(__git_ps1 ” (%s)”)]\$ ‘
export PROMPT_COMMAND=’echo -ne “\033]0;{PWD/#$HOME/~}\007”’
Also, note that “source ~/.bashrc” can be written as “. ~/.bashrc”. Handy shortcut!
Need to do this every time we want to use it.
UPDATE: entered this into .bash_profile so we don’t have to keep doing it.
git completion:
http://lifeon.biggerplanet.com/git-flow-and-git-completion-on-mac-os-x
Sidenote: that this “make && make install” means that “make install” will not be run if “make” does not run successfully.
Re-install rvm
Note, had to delete existing references to rvm everywhere!
Handy commands:
rvm reload
and
rvm notes
Ensure rvm is loadable as a function by adding this to my .bash_profile:
[[ -s “/Users/user/.rvm/scripts/rvm” ]] && source “/Users/user/.rvm/scripts/rvm” # Load RVM into a shell session *as a function*
and then logout / login (rather than sourcing .bash_profile.
Check rvm is installed correctly:
type rvm | head -1
should give:
“rvm is a function” if installed correctly.
Note, gems are packages.
Rails is supplied as a gem.
Ruby is version 1.8.7
So, to manage ruby versions (if necessary in future), we’ll use rbenv
To start, install Homebrew (“Homebrew is the easiest and most flexible way to install the UNIX tools Apple didn’t include with OS X.”)
But see also “Homebrew vs MacPorts”: http://tedwise.com/2010/08/28/homebrew-vs-macports/
/usr/bin/ruby -e “$(curl -fsSL https://raw.github.com/gist/323731)”
Then rbenv ‘cos was suggested by someone in #RubyOnRails. Also, Dreamhost Wiki said Passenger and rvm did not work together.
Note, rbenv is incompatible with rvm.
So, uninstall rvm using:
rvm implode
http://stackoverflow.com/questions/3950260/howto-uninstall-rvm
and remove any rvm references from .bash_profile
And install rbenv
https://github.com/sstephenson/rbenv#section_2
Sidenote: “exec $SHELL” to restart your shell.
NB: to upgrade rbenv, use:
cd ~/.rbenv; git pull
However, after going back to the #RubyOnRails IRC channel, got a negative comment about rbenv. And Passenger doesn’t support multiple ruby versions. Does support rvm.
So, installing rvm again!
Note, this only takes a couple of minutes.
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
(http://beginrescueend.com/)
and
source ~/.bash_profile
Install ruby via rvm
rvm install 1.9.2
Sidenote:
This gets YAML which is a data serialisation language (NB it forbids tabs as they are treated differently by different editors and tools).
YAML is like XML or JSON. But unlike XML, it’s easier to read, faster to encode and decode, takes less memory than XML when decoding.
See: http://webignition.net/articles/xml-vs-yaml-vs-json-a-study-to-find-answers/
Ruby install was trivial.
Then a gemset:
rvm —create use 1.9.2@rails3tutorial
rvm —default use 1.9.2@rails3tutorial
And finally rails:
gem install rails 3.0.0
BUT this did not work so smoothly! Errors with zlib, e.g.
ERROR: Loading command: update (LoadError)
no such file to load — zlib
ERROR: While executing gem … (NameError)
uninitialized constant Gem::Commands::UpdateCommand
So, from here: https://rvm.beginrescueend.com/packages/zlib/
$ rvm pkg install zlib
$ rvm reinstall 1.9.2 —with-zlib-dir=$rvm_path/usr
BUT same error.
Not much help from IRC other than another post on installing rails:
http://ryanbigg.com/2011/06/mac-os-x-ruby-rvm-rails-and-you/
Stackoverflow post:
http://stackoverflow.com/questions/2441248/rvm-ruby-1-9-1-install-cant-locate-zlib-but-its-runtime-and-dev-library-are-the
rvm pkg install zlib
rvm remove 1.9.1
rvm install 1.9.1 -C —with-zlib-dir=$rvm_path/usr
(note: “rvm package” was renamed “rvm pkg” in 1.6.25)
Still no joy.
However, we’re getting an expanded error message. I.e.
Error loading gem paths on load path in gem_prelude
can’t modify frozen string
<internal:gem_prelude>:69:in `force_encoding’
…
and then the zlib error.
No idea if this was the fix but it seems to be working after this:
rvm pkg install zlib
rvm remove 1.9.1
rvm install 1.9.3 -C —with-zlib-dir=$rvm_path/usr
Day 3 of Ruby / Rails install
17th Feb 2011
Following http://www.christopherirish.com/2011/09/02/ruby-1-9-2-segmentation-fault-and-openssl/
and also mentioned by mpapis on IRC (i.e. that it might be openssl).
Note, also handy: http://root2linux.com/2011/12/how-to-upgrade-ruby-1-8-7-into-ruby-1-9-2-using-rvm-on-ubuntu-10-10/
So:
which openssl
rvm use system
ruby -v
» ruby 1.8.7
rvm —default system
rvm remove 1.9.3
rvm pkg install zlib
rvm install 1.9.3 —with-openssl-dir=/opt/local/bin/openssl —with-zlib-dir=$rvm_path/usr
rvm requirements
Which says to do:
brew install libksba
rvm system ; rvm gemset export system.gems ; rvm 1.9.3 ; rvm gemset import system.gems
Then:
rvm use 1.9.3
rvm —default 1.9.3
And:
rvm pkg install zlib
rails new todos
/Users/user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require’: cannot load such file — zlib (LoadError)
From here:
http://stackoverflow.com/questions/2441248/rvm-ruby-1-9-1-install-cant-locate-zlib-but-its-runtime-and-dev-library-are-the
rvm install 1.9.3 —with-openssl-dir=/opt/local/bin/openssl -C —with-zlib-dir=$rvm_path/usr
STARTING ALL OVER AGAIN:
Delete rvm with
rvm implode
and then remove from .bash_profile
http://stackoverflow.com/questions/3558656/how-to-remove-rvm-ruby-version-manager-from-my-system
Reinstall rvm.
Download and install standalone gcc as mentioned for Xcode 4.2.1 here:
http://rocksolidwebdesign.com/notes-and-fixes/ruby-xcode/
Then:
rvm pkg install readline
rvm pkg install iconv
(http://rocksolidwebdesign.com/notes-and-fixes/mac-rvm/)
Note: rvm will automatically use gcc-4.2 (i.e. the standalone gcc we’ve just downloaded and installed) if it’s available.
rvm pkg install zlib
rvm install 1.9.3-p125 —with-openssl-dir=/opt/local/bin/openssl -C —with-zlib-dir=$rvm_path/usr —with-opt-dir=$HOME/.rvm/usr
Runs into this problem:
curl: (7) Failed to connect to 221.186.184.68: Host is down
BUT, trying with web browser and FTP and can login fine.
So, try using netcat:
http://www.linuxquestions.org/questions/linux-newbie-8/curl-7-couldnt-connect-to-host-wget-failed-connection-refused-728866/
But no net cat.
Install via brew.
brew install netcat
Installs net cat BUT have this warning:
/usr/local/bin/brew:74: warning: Insecure world writable dir /usr/local/Library in PATH, mode 040777
Google turns up this: http://stackoverflow.com/questions/4574927/running-brew-generates-warnings
which recommends:
sudo chmod 755 /usr/local/bin
Also fixed:
sudo chmod 755 /usr/local/Library
rvm requirements
brew install libksba
rvm system ; rvm gemset export system.gems ; rvm 1.9.3 ; rvm gemset import system.gems
Got these errors:
====
[~]$ rvm system ; rvm gemset export system.gems ; rvm 1.9.3 ; rvm gemset import system.gems
Exporting current environments gemset to system.gems
Installing gems listed in system.gems file…
installing abstract 1.0.0…
Error running ‘GEM_HOME=’/Users/user/.rvm/gems/ruby-1.9.3-p125’ GEM_PATH=’/Users/user/.rvm/gems/ruby-1.9.3-p125’ gem install —remote abstract -v1.0.0 ‘, please read /Users/user/.rvm/log/ruby-1.9.3-p125/gem.install.log
abstract 1.0.0 failed to install ( output logged to: /Users/user/.rvm/log/ruby-1.9.3-p125/gem.install.log )
installing actionmailer 3.0.5…
Error running ‘GEM_HOME=’/Users/user/.rvm/gems/ruby-1.9.3-p125’ GEM_PATH=’/Users/user/.rvm/gems/ruby-1.9.3-p125’ gem install —remote actionmailer -v3.0.5 ‘, please read /Users/user/.rvm/log/ruby-1.9.3-p125/gem.install.log
actionmailer 3.0.5 failed to install ( output logged to: /Users/user/.rvm/log/ruby-1.9.3-p125/gem.install.log )
installing actionpack 3.0.5…
Error running ‘GEM_HOME=’/Users/user/.rvm/gems/ruby-1.9.3-p125’ GEM_PATH=’/Users/user/.rvm/gems/ruby-1.9.3-p125’ gem install —remote actionpack -v3.0.5 ‘, please read /Users/user/.rvm/log/ruby-1.9.3-p125/gem.install.log
actionpack 3.0.5 failed to install ( output logged to: /Users/user/.rvm/log/ruby-1.9.3-p125/gem.install.log )
installing activemodel 3.0.5…
Error running ‘GEM_HOME=’/Users/user/.rvm/gems/ruby-1.9.3-p125’ GEM_PATH=’/Users/user/.rvm/gems/ruby-1.9.3-p125’ gem install —remote activemodel -v3.0.5 ‘, please read /Users/user/.rvm/log/ruby-1.9.3-p125/gem.install.log
==== log file ====
[2012-02-17 14:29:12] GEM_HOME=’/Users/user/.rvm/gems/ruby-1.9.3-p125’ GEM_PATH=’/Users/user/.rvm/gems/ruby-1.9.3-p125’ gem install —remote capistrano -v2.5.19
/Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require’: Interrupt
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require’
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/command.rb:8:in `<top (required)>’
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require’
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require’
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/command_manager.rb:7:in `<top (required)>’
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require’
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require’
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:8:in `<top (required)>’
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require’
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require’
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/bin/gem:13:in `<main>’
/Users/user/.rvm/log/ruby-1.9.3-p125/gem.install.log (END)
====
End of Day 3.
Gave up on rvm, rbenv. Made sure I was using the system version of ruby (ruby 1.8.7):
rvm use system
Then just did this:
sudo gem install rails
And:
rails new todos
Then:
rails g scaffold todo name:string due_on:date completed:boolean
rake db:migrate
And:
rails s
Point your web browser at http://localhost:3000 and you should see a page welcoming you to Rails. To start managing your todos, go to http://localhost:3000/todos.
When you’re done, you can stop the Rails app by typing CTRL-C in the command prompt where you started the app.
Courtesy of: http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac