{"id":761,"date":"2009-09-08T03:47:13","date_gmt":"2009-09-08T08:47:13","guid":{"rendered":"http:\/\/blogs.law.harvard.edu\/hoanga\/?p=761"},"modified":"2009-09-08T03:47:13","modified_gmt":"2009-09-08T08:47:13","slug":"getting-ruby-191p243-to-work-on-os-x-1058-with-japanese-input-support-on-irb","status":"publish","type":"post","link":"https:\/\/archive.blogs.harvard.edu\/hoanga\/2009\/09\/08\/getting-ruby-191p243-to-work-on-os-x-1058-with-japanese-input-support-on-irb\/","title":{"rendered":"Getting Ruby 1.9.1p243 to work on OS X 10.5.8 with Japanese input support on irb"},"content":{"rendered":"<p>Awhile back I installed Ruby 1.9.1 in such a way as to co-exist with my current Ruby installation [1], [2] (I should use rvm [3] these days&#8230;)<\/p>\n<p>However, one issue that cropped up during an IRB session was I could not copy and paste Japanese characters into the IRB repl.  This is very very painful for my day to day use with Ruby (Imagine not being able to use the &#8216;|&#8217; character while writing UNIX pipelines). <\/p>\n<p>Below is an example of me trying to enter the character \u3042 into IRB and watching it fail.<\/p>\n<blockquote>\n<pre>\r\n$ irb\r\nirb(main):001:0&gt; ab = \"?\"    &lt;---- Tried entering the character \u3042\r\nSyntaxError: (irb):1: invalid multibyte char (UTF-8)\r\n(irb):1: unterminated string meets end of file\r\nfrom \/usr\/local\/bin\/irb19:12:in `'\r\n<\/pre>\n<\/blockquote>\n<p>After a lot of head scritching I was able to narrow it down to something with readline:<\/p>\n<blockquote>\n<pre>\r\n$ irb --noreadline\r\nirb(main):002:0&gt; ab = \"\u3042\"\r\n=&gt; \"\u3042\"\r\nirb(main):003:0&gt; \r\n<\/pre>\n<\/blockquote>\n<p>After some more digging into the issue.  The root cause seems to be the lack of GNU readline.  By default, Ruby will link in the system installed readline library on OS X which is called <a href=\"http:\/\/thrysoee.dk\/editline\/\">editline<\/a> [4].  Unfortunately, editline does not support UTF8 or multi-byte character sets which makes this a no-go for daily usage.<\/p>\n<p>Most of the other references suggest downloading readline from source and installing into <em>\/usr\/local<\/em> however I believe this defeats the purpose of using something like <a href=\"http:\/\/www.macports.org\">MacPorts<\/a>.  After a bit of finagling I found that this is the invocation to get things working.<\/p>\n<blockquote>\n<pre>\r\nwget ftp:\/\/ftp.ruby-lang.org\/pub\/ruby\/1.9\/ruby-1.9.1-p243.tar.gz\r\ntar xvzf ruby-1.9.1-p243.tar.gz\r\ncd ruby-1.9.1-p243\r\n# Don't trust MacPorts version of autoconf because it somehow nuked the\r\n# --with-readline-dir option\r\n\/usr\/bin\/autoconf\r\n.\/configure --with-readline-dir=\/opt\/local --enable-shared --program-suffix=19 --enable-pthread\r\nmake\r\nsudo make install\r\n<\/pre>\n<\/blockquote>\n<p>I have it wrapped up in a script which you can <a href=\"http:\/\/gist.github.com\/180805\">see here<\/a>.<\/p>\n<p>References<\/p>\n<p>[1] http:\/\/wonko.com\/post\/how-to-compile-ruby-191<br \/>\n[2] http:\/\/frozenplague.net\/2009\/01\/ruby-191-rubygems-rails\/<br \/>\n[3] http:\/\/rvm.beginrescueend.com\/<br \/>\n[4] http:\/\/thrysoee.dk\/editline\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Awhile back I installed Ruby 1.9.1 in such a way as to co-exist with my current Ruby installation [1], [2] (I should use rvm [3] these days&#8230;) However, one issue that cropped up during an IRB session was I could not copy and paste Japanese characters into the IRB repl. This is very very painful [&hellip;]<\/p>\n","protected":false},"author":703,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1216,364,1214,972,615],"tags":[],"class_list":["post-761","post","type-post","status-publish","format-standard","hentry","category-fixes","category-japan","category-osx","category-programming","category-ruby"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/posts\/761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/users\/703"}],"replies":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/comments?post=761"}],"version-history":[{"count":9,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/posts\/761\/revisions"}],"predecessor-version":[{"id":772,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/posts\/761\/revisions\/772"}],"wp:attachment":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/media?parent=761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/categories?post=761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/tags?post=761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}