Tuesday, April 29, 2014

Upgrading to ruby 2.1.1 on OSX

I prefer to use rbenv to manage my system rubies.

Commands to install new version of ruby via rbenv


$ brew update
$ brew upgrade ruby-build
$ rbenv install 2.1.1
$ rbenv rehash


If you notices compilation errors such as the following, then provide a reference to the readline dynamic library via the RUBY_CONFIGURE_OPTS environment variable.

Compilation Error


linking shared-object objspace.bundle
readline.c: In function ‘Init_readline’:
readline.c:1977: error: ‘Function’ undeclared (first use in this function)
readline.c:1977: error: (Each undeclared identifier is reported only once
readline.c:1977: error: for each function it appears in.)
readline.c:1977: error: expected expression before ‘)’ token
make[2]: *** [readline.o] Error 1
make[1]: *** [ext/readline/all] Error 2

Pass readline's dynamic library reference to rbenv install command


(RUBY_CONFIGURE_OPTS=--with-readline-dir="/usr/lib/libreadline.dylib" rbenv install 2.1.1)

Console

Here's the console log that shows errors along the way and the eventual successful installation of ruby 2.1.1.

$ brew update
Already up-to-date.
$ brew upgrade ruby-build
==> Upgrading 1 outdated package, with result:
ruby-build 20140420
==> Upgrading ruby-build
==> Downloading https://github.com/sstephenson/ruby-build/archive/v20140420.tar.gz
######################################################################## 100.0%
==> ./install.sh
🍺  /usr/local/Cellar/ruby-build/20140420: 115 files, 492K, built in 2 seconds
$ rbenv install 2.1.1
Downloading ruby-2.1.1.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/e57fdbb8ed56e70c43f39c79da1654b2
Installing ruby-2.1.1...

BUILD FAILED

Inspect or clean up the working tree at /var/folders/kg/3_wp8l4j6cv758ldc2v6n07c0000gn/T/ruby-build.20140429162005.40162
Results logged to /var/folders/kg/3_wp8l4j6cv758ldc2v6n07c0000gn/T/ruby-build.20140429162005.40162.log

Last 10 log lines:
compiling ossl_x509crl.c
compiling ossl_x509ext.c
compiling ossl_x509name.c
compiling ossl_x509req.c
compiling ossl_x509revoked.c
compiling ossl_x509store.c
installing default openssl libraries
linking shared-object openssl.bundle
linking shared-object nkf.bundle
make: *** [build-ext] Error 2
$ subl /var/folders/kg/3_wp8l4j6cv758ldc2v6n07c0000gn/T/ruby-build.20140429162005.40162.log
$ (RUBY_CONFIGURE_OPTS=--with-readline-dir="/usr/lib/libreadline.so" rbenv install 2.1.1)
Downloading ruby-2.1.1.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/e57fdbb8ed56e70c43f39c79da1654b2
Installing ruby-2.1.1...
^C
BUILD FAILED

Inspect or clean up the working tree at /var/folders/kg/3_wp8l4j6cv758ldc2v6n07c0000gn/T/ruby-build.20140429162319.57115
Results logged to /var/folders/kg/3_wp8l4j6cv758ldc2v6n07c0000gn/T/ruby-build.20140429162319.57115.log

Last 10 log lines:
checking for dlopen in -ldl... yes
checking for shl_load in -ldld... no
checking for shutdown in -lsocket... no
checking for dirent.h that defines DIR... yes
checking for library containing opendir... none required
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking limits.h usability... yes
checking limits.h presence...
BUILD FAILED

Inspect or clean up the working tree at /var/folders/kg/3_wp8l4j6cv758ldc2v6n07c0000gn/T/ruby-build.20140429162319.57115
Results logged to /var/folders/kg/3_wp8l4j6cv758ldc2v6n07c0000gn/T/ruby-build.20140429162319.57115.log

Last 10 log lines:
checking for dlopen in -ldl... yes
checking for shl_load in -ldld... no
checking for shutdown in -lsocket... no
checking for dirent.h that defines DIR... yes
checking for library containing opendir... none required
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking limits.h usability... yes
checking limits.h presence... $
$ (RUBY_CONFIGURE_OPTS=--with-readline-dir="/usr/lib/libreadline.so" rbenv install 2.1.1)
$ find /usr -name  "libreadline.*"
/usr/lib/libreadline.dylib
/usr/local/Cellar/readline/6.2.4/lib/libreadline.6.2.dylib
/usr/local/Cellar/readline/6.2.4/lib/libreadline.6.dylib
/usr/local/Cellar/readline/6.2.4/lib/libreadline.a
/usr/local/Cellar/readline/6.2.4/lib/libreadline.dylib
/usr/local/Cellar/readline/6.3.3/lib/libreadline.6.2.dylib
/usr/local/Cellar/readline/6.3.3/lib/libreadline.6.3.dylib
/usr/local/Cellar/readline/6.3.3/lib/libreadline.6.dylib
/usr/local/Cellar/readline/6.3.3/lib/libreadline.a
/usr/local/Cellar/readline/6.3.3/lib/libreadline.dylib
find: /usr/local/var/run/nginx/client_body_temp: Permission denied
find: /usr/local/var/run/nginx/fastcgi_temp: Permission denied
find: /usr/local/var/run/nginx/proxy_temp: Permission denied
find: /usr/local/var/run/nginx/scgi_temp: Permission denied
find: /usr/local/var/run/nginx/uwsgi_temp: Permission denied
find: /usr/sbin/authserver: Permission denied
$ brew install openssl libyaml
Warning: openssl-1.0.1g already installed
Warning: libyaml-0.1.6 already installed
$ brew tap homebrew/dupes && brew install apple-gcc42
Warning: Already tapped!
Warning: apple-gcc42-4.2.1-5666.3 already installed
$ ls -l /etc/gemrc
ls: /etc/gemrc: No such file or directory
$ ls -l /usr/lib/libreadline.dylib
lrwxr-xr-x  1 root  wheel  15 Jan  9 23:44 /usr/lib/libreadline.dylib -> libedit.3.dylib
$ (RUBY_CONFIGURE_OPTS=--with-readline-dir="/usr/lib/libreadline.dylib" rbenv install 2.1.1)
Downloading ruby-2.1.1.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/e57fdbb8ed56e70c43f39c79da1654b2
Installing ruby-2.1.1...
Installed ruby-2.1.1 to /Users/lex/.rbenv/versions/2.1.1
$ rbenv global 2.1.1
$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
$ rbenv versions
  system
  1.9.3-p327
  1.9.3-p448
  1.9.3-p484
* 2.1.1 (set by /Users/lex/.rbenv/version)
  rbx-2.2.3
  ruby-with-ssl-2.0.0-p353


Full set of commands to run to install Ruby 2.1.1 on OSX


brew update
brew doctor
brew upgrade ruby-build
brew install openssl libyaml
brew tap homebrew/dupes && brew install apple-gcc42
ls -l /usr/lib/libreadline.dylib
(RUBY_CONFIGURE_OPTS=--with-readline-dir="/usr/lib/libreadline.dylib" rbenv install 2.1.1)
rbenv rehash
rbenv versions
rbenv global 2.1.1
ruby -v
gem install rb-readline
gem uninstall bundler
gem install bundler


Fix Up/Down Arrow Keys in irb console

Are your Up/Down arrow keys broken in irb?

Do you see the following in your irb console when you hit the up arrow key and then the down arrow key?

^[[A^[[B

Just install the rb-readline gem.

References

https://github.com/sstephenson/ruby-build/wiki

Saturday, April 5, 2014

Markdown (and github markdown) Syntax

Markdown is a text-to-HTML conversion tool for web writers.

Markdown file extension is .md

You often see the file README.md in the root of github projects.

markdown syntax tips

Headers


# Header - level 1 #
## Header - level 2 ##
### Header - level 3 ###
(and so on)

Blockquote


> Quoted text

Code

Inline

Escape `inline code` with backticks

Github Fenced Code Blocks

Just wrap your code in ```

```
function test() {
  console.log("notice the blank line before this function?");
}
```

Github Language Syntax Highlighting


```ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
```


We use Linguist to perform language detection and syntax highlighting. You can find out which keywords are valid by perusing the languages YAML file.

Tables

Simple Table


First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell

Table with Cell Alignment


| Left-Aligned  | Center Aligned  | Right Aligned |
| :------------ |:---------------:| -----:|
| col 3 is      | some wordy text | $1600 |
| col 2 is      | centered        |   $12 |
| zebra stripes | are neat        |    $1 |

Lists

Unordered Lists


* Use 
* The 
* Asterisk

Ordered Lists


1. Use
1. Number
1. Followed by Period

Horizontal Lines

Three or more dashes

---

Emphasis

Itialic


*italic*
**bold**

Escape Emphasis

Use backslash

not \*itialic\*
not \*\*bold\*\*

Github Striketrhough

Double squigly used to ~~strikethrough text~~

Thursday, April 3, 2014

Downloads for Apple Developers

https://developer.apple.com/downloads/index.action

I recently needed to download the latest xcode developer command line tools directly because I got this error message ...

Xcode is not currently available from the Software Update server


 ...when attempting to run xcode-select --install