Skip to content

Easy Ruby 1.9.3 Install

Easy Ruby 1.9.3 Install
We have noticed some hiccups even with Mac users because Ruby 1.9.3 is not preinstalled. This is my very personal path to installing Ruby 1.9.3 on a rental MacBook Pro that I had to prepare for Cloud Foundry.

1. RVM vs Homebrew: Many people prefer RVM, and I see the benefits. However, I was hitting too many roadblocks and remember my last install using Homebrew. I recall that it was a pretty smooth process. That is what I will use here.
2. About my Mac: I happen to be using a rental MacBook Pro with Mac OS X 10.7.5 (Lion)
3. Download Ruby: www.ruby-lang.org/en/downloads: Scroll down to the section, “Compiling Ruby – Source code”. In my case, I downloaded and opened the link “Ruby 1.9.3-p448”
4. Install Xcode: If you don’t have Xcode, go the AppStore and search “Xcode”. Complete the free install. I installed Xcode 4.6.3
5. Update the Xcode Command Line Tools: Open Xcode and choose “Preferences” from the Xcode drop down menu in the top left of your screen. When the preferences window opens, select “Downloads” from the top menu of icons. You should see a line that says “Command Line Tools”. Click the button to the right that says “Install”. Wait for it to complete.
6. Install Homebrew: Go to brew.sh and follow the instructions at the bottom of the page under “Install Homebrew”. If you have never opened your Terminal before, go to the search (magnifying glass) icon at the top right corner of the your Mac screen, click on it, and type in “Terminal”. You should find and be able to click on the option “Terminal” which will have a black screen icon.
At the Terminal prompt $, type or paste in
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
as instructed on the website.
I followed the instructions that appeared and entered
$ brew doctor
In my case, it suggested that I enter
$ sudo mv /opt/local ~/macports
6. Install ruby 1.9.3: I found this site useful: sam.roon.io/how-to-install-ruby-193
Under the section “Installing rbenv”, he indicates that you have to install GCC.
7. Install GCC: I followed Sam Roon’s instructions and went to https://github.com/kennethreitz/osx-gcc-installer/downloads I selected GCC-10.7-v2.pkg. Download it, open it, and click on the yellow box icon to install it.
8. Complete Ruby 1.9.3 Install: Followed the next steps on sam.roon.io/how-to-install-ruby-193
$ brew update
$ brew install rbenv
$ brew install ruby-build
$ rbenv install 1.9.3-p448
Finally, I followed the instructions to make ruby 1.9.3 my default version by entering
$ rbenv global 1.9.3-p448

9. Install Cloud Foundry Gem / Potential Write Problems: To install the cf gem, I continued with gem install cf as mentioned on this post:
$ gem install cf
However, with my rental laptop, I hit the problem “You don’t have write permissions into … (Gems directory)
I found this solved the problem:
http://stackoverflow.com/questions/2893889/how-do-i-fix-the-you-dont-have-write-permissions-into-the-usr-bin-directory
Entered:
$ sudo gem install cf --pre
and it worked.
Now I’m ready to cf login and push my app!
10. Pushing your first app to Cloud Foundry! Here is a summary of my previous post. Check this post in case  you hit any of the same errors that I got.
Step 1: Create a new account. Go to cloudfoundry.com
Click on the “free trial” button
Enter email address and Promo code (you can use “preshavedyak”)
Check your email and click on the link in the email from Cloud Foundry
Create a password

Step 2: Update your gems, target, and then log in.
I followed the steps on http://docs.cloudfoundry.com/docs/dotcom/getting-started.html#install-cf
$ gem install cf
$ cf target api.run.pivotal.io
$ cf login

From the option listed, I chose “1” (development)

Step 3: Set up for your ruby sinatra app.
You don’t have to push a ruby sinatra app. Cloud Foundry supports Java, Spring, Groovy and Grails, Scala, Ruby on Rails, Node and other languages and runtimes, but I happen to have a ruby sinatra app.
So I decided to read further on http://docs.cloudfoundry.com/docs/using/deploying-apps/ruby/
It told me to go to http://bundler.io/
I followed these steps:
a) $ gem install bundler
b) Create doc “Gemfile” (no extension to the file) and save this text in the file:
source 'https://rubygems.org'
gem 'sinatra'
ruby '1.9.3'

Save this file in the folder with my baconpancakesv2.rb app

$ bundle install
This creates the Gemfile.lock file

c) Update the baconpancakes.rb app

I renamed it baconpancakesv2.rb
I followed the steps on http://www.sinatrarb.com/extensions.html

Here is the code for baconpancakesv2.rb:
class YakApp < Sinatra::Base
get '/' do
def youtube_embed(youtube_url)
if youtube_url[/youtu\.be\/([^\?]*)/]
youtube_id = $1
else
# Regex from # http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url/4811367#4811367
youtube_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
youtube_id = $5
end
%Q{[youtube https://www.youtube.com/watch?v=#youtube_id&w=560&h=315]}
end
"<h1>Bacon Pancakes from Cloud Foundry</h1>"+youtube_embed('youtu.be/zalYJacOhpo')
end
end

d) Create config.ru

Return to http://docs.cloudfoundry.com/docs/using/deploying-apps/ruby/
Follow instructions to create config.ru file.
Also follow the instructions on http://www.sinatrarb.com/extensions.html
So the config.ru file will include:
require 'sinatra'
require 'sinatra/base'
require './baconpancakesv2'
map '/' do
run YakApp
end

Step 4: Push your app.
So now you should have a directory that has these 4 files:

  • rb app
  • Gemfile
  • Gemfile.lock
  • config.ru

From your Terminal window, make sure you are in the directory with these files.
Now do the cf push from that directory.
$ cf push
Name> baconpancakesv2
Instances>1
Memory Limit>256M
Subdomain>baconpancakesv2
Domain>cfapps.io
Create services for application?>n
Save configurations?>n

You should be able to push your app to Cloud Foundry. If you used my app, it should look like this: http://baconpancakesv2.cfapps.io

Of course, this is a limited case. Please consult the Cloud Foundry documentation for further info.
Also check out Andy Piper’s github repo for this same app: https://github.com/andypiper/yak/tree/andyp
Thanks to Andy for his help!

Step 6: Manage your account in the browser.
Once you have your account. Don’t forget to check out your new account console in the browser. Pretty nice!

Hello World on Cloud Foundry v2

It’s been very busy around here and I’ve been lagging behind on the updates to Cloud Foundry v2. If you’re like me, hopefully you will find this a useful update going from way-old vmc on v1 to cf on v2:

I’m going to create a new account on Cloud Foundry and push my good old bacon pancakes ruby sinatra app to my new account.

Step 1: Create a new account.  Creating a new account on Cloud Foundry, especially with a promo code, is much easier now. No more temporary passwords that were sometimes hard to read.

Go to cloudfoundry.com
Click on the “free trial” button
Enter email address and Promo code (you can use “preshavedyak”)
Check your email and click on the link in the email from Cloud Foundry
Create a password

Now you have an account and password!

Step 2: Update your gems, target, and then log in.

I followed the steps on http://docs.cloudfoundry.com/docs/dotcom/getting-started.html#install-cf

$ gem install cf
$ cf target api.run.pivotal.io
$ cf login

From the option listed, I chose “1” (development)

Step 3: Push your app. First I was lazy and tried to see if my existing app would push as is.

$ cf push
Name> baconpancakesv2
Instances>1
Memory Limit>256M
Subdomain>baconpancakesv2
Domain>cfapps.io
Create services for application?>n
Save configurations?>n

Error for the lazy! I got this:

Error:
—–> Downloaded app package (4.0K)
/var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:44:in `build_pack’: Unable to detect a supported application type (RuntimeError)
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:26:in `block in compile_with_timeout’
from /usr/lib/ruby/1.9.1/timeout.rb:68:in `timeout’
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:25:in `compile_with_timeout’
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:16:in `block in stage_application’
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:12:in `chdir’
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:12:in `stage_application’
from /var/vcap/packages/dea_next/buildpacks/bin/run:10:in `<main>’
Checking status of app ‘baconpancakestest’…Application failed to stage

Step 4: Set up for your ruby sinatra app.

So I decided to read further on http://docs.cloudfoundry.com/docs/using/deploying-apps/ruby/

It told me to go to http://bundler.io/
I followed these steps:

a) $ gem install bundler
b) Create doc “Gemfile” (no extension to the file) and save this text in the file:
source 'https://rubygems.org'

The site says to add the following:
gem ‘nokogiri’
gem ‘rack’, ‘~>1.1’
gem ‘rspec’, :require => ‘spec’

In our case, it is a ruby/sinatra app, so I paste the following in the Gemfile:
source 'https://rubygems.org'
gem 'sinatra'

Save this file in the folder with my baconpancakesv2.rb app

$ bundle install
Skipped $ git add Gemfile Gemfile.lock

Error: I needed to add the ruby version to the Gemfile. In my case, it is ruby ‘1.9.3’
Updated Gemfile to say:
source 'https://rubygems.org'
gem 'sinatra'
ruby '1.9.3'

$ bundle install
This creates the Gemfile.lock file

c) Update the baconpancakes.rb app

I renamed it baconpancakesv2.rb
I followed the steps on http://www.sinatrarb.com/extensions.html
Change the first line of the app:
Delete: require ‘sinatra’
Replace with: class YakApp < Sinatra::Base
and add “end” in the last line

Here is the code for baconpancakesv2.rb:
class YakApp < Sinatra::Base
get '/' do
def youtube_embed(youtube_url)
if youtube_url[/youtu\.be\/([^\?]*)/]
youtube_id = $1
else
# Regex from # http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url/4811367#4811367
youtube_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
youtube_id = $5
end
%Q{[youtube https://www.youtube.com/watch?v=#youtube_id&w=560&h=315]}
end
"<h1>Bacon Pancakes from Cloud Foundry</h1>"+youtube_embed('youtu.be/zalYJacOhpo')
end
end

d) Create config.ru

Return to http://docs.cloudfoundry.com/docs/using/deploying-apps/ruby/
Follow instructions to create config.ru file.
Site says:
require ‘./hello_world’
run HelloWorld.new

In my case, for our sinatra app, I include the following:
require 'sinatra'
require './baconpancakesv2' (Make sure this is your own directory name)

map ‘/’ do
run YakApp
end

Also follow the instructions on http://www.sinatrarb.com/extensions.html
So the config.ru file will include:
require 'sinatra'
require 'sinatra/base'
require './baconpancakesv2'
map '/' do
run YakApp
end

Step 5: Try to push the app the right way.

So now you should have a directory that has these 4 files:

  • rb app
  • Gemfile
  • Gemfile.lock
  • config.ru

Now do the cf push from that directory. You should be able to push your app to Cloud Foundry. If you used my app, it should look like this: http://baconpancakesv2.cfapps.io

Of course, this is a limited case. Please consult the Cloud Foundry documentation for further info.

Also check out Andy Piper’s github repo for this same app: https://github.com/andypiper/yak/tree/andyp

Thanks to Andy for his help!

Step 6: Manage your account in the browser.

Once you have your account. Don’t forget to check out your new account console in the browser. Pretty nice!

Focus on the Code, Leave the Infrastructure to Cloud Foundry

From the Silicon Angle article, Focus on the Code, Leave the Infrastructure to Cloud Foundry

How to create Turntable FM bots on Cloud Foundry, node.js

Cool video by angryrancor and funny at the end ;)

March 5, 2013: Dr. Nic on “Build your own Heroku with open source Cloud Foundry”

March 5, 2013
6:30 pm PST
Location: LinkedIn, 2051 Stierlin Ct, Mountain View, CA
Register: http://www.meetup.com/silicon-valley-ruby/events/104290372/

Yak Shaving Hello World! ;)

From the Alameda County (first) Hackathon

Ren & Stimpy Yak Shaving

Barebones Cloud Foundry Youtube Post #2.5 (Ruby)

It’s pretty easy to get started with Cloud Foundry, but here’s also a 10 min barebones version we shared at the Alameda County Hackathon 2012 (record is 7 mins!)

This is a “half project” because I have not changed any of the instructions from the Barebones Hello World in Ruby.

require 'rubygems'
require 'sinatra'

get '/' do

def youtube_embed(youtube_url)

if youtube_url
[/youtu\.be\/([^\?]*)/]
youtube_id = $1

else

# Regex from # http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url/4811367#4811367
youtube_url
[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
youtube_id = $5

end
%Q{
<iframe title="YouTube video player" width="560" height="315" src="http://www.youtube.com/embed/#{ youtube_id }" frameborder="0" allowfullscreen></iframe>}
end

"<
h1>Bacon Pancakes from Cloud Foundry</h1>"+youtube_embed('youtu.be/zalYJacOhpo')
end

I just changed the Ruby app code to post a youtube link. You can copy and paste this code into your Ruby app too!

Once this process is complete, copy and paste your new url into a browser (eg. in my case it is http://baconpancakes.cloudfoundry.com/)
Voila’! Bare bare bones Cloud Foundry app push completed.

(Thanks to http://stackoverflow.com/users/13831/douglas-f-shearer for his post on stackoverflow)

NOTE: Yes, this is a very very limited case. If you encounter issues, please consult these resources:

http://docs.cloudfoundry.com/getting-started.html

http://support.cloudfoundry.com/home

http://stackoverflow.com/questions/tagged/cloudfoundry

Follow

Get every new post delivered to your Inbox.