Hello Ruby My Old Friend
I’ve not directly been programming Ruby — so “old friend” is a stretch. But I’ve poked at UI code inside Ruby apps, and needed to run them locally. And I had years using Jekyll for various blogs, including this one. I see now that I figured out a lot when setting up a new MacBook four years ago. I should have checked out those notes earlier this week, when I was prepping my work laptop for Ruby. 😅
Previously, I’ve preferred to set up a version manager from the start — not waiting to see if the need for different Ruby versions appear. It doesn’t happen at convenient times. I’m guessing it wildly depends if the need is inevitable or not, but this is either way just one of those things I have liked to prepare for. Being ready to install and easily switch between different versions, all set up and ready to go.
The README for rbenv
is really good. It’s got the best explanation of PATH and shims I know about. The way the steps are set up tripped me up a bit though, at one point I thought I had installed Ruby when I had only run a command to list available stable versions. Command and recipe cheat sheet:
Check current status
brew list
to check if there is something related to Ruby there already- Will
ruby -v
show me the older version that came with the system? Yes - See that
which ruby
returns/usr/bin/ruby
for the system Ruby gem env
also shows a lot of stuff!
Set up the version manager
- Install rbenv with
brew install rbenv
- Run
rbenv init
- Follow the instructions in the output from that command
- Open a new terminal window
- Verify with the rbenv-doctor script from the README 🟢
Install and set a Ruby version
- Install a Ruby version, for example with
rbenv install 3.0.2
- Set version! For example with
rbenv global 3.0.2
- …or
rbenv local 2.7.4
for a specific project
Check updated status
brew list
will now show both rbenv and ruby-buildruby -v
will now return the specific version that I setrbenv version
will return the current version of Rubyrbenv versions
lists version(s) of Ruby known to rbenv on my laptoprbenv --version
to see the version of rbenv itselfgem env
to inspect new Ruby setup and check differences from beforels -la
is my friend to follow which hidden directories and files are createdcat .rbenv/version
will show that 3.0.2 is set globally
I like meticulously checking what’s what and where, comparing before and after. This makes it easier to understand what I’m actually doing — instead of throwing random commands out and hoping for the best. When I learn what is where and why, I am also capable of debugging when something goes wrong.