A Clean Way to Run Multiple Versions of Python & Ruby

Solution

Use pyenv and rbenv

How It Works?

These tools create a shim (or think of softlinks) for a version of the software. You can choose to run a version globally or locally in a shell. Switch to a version anytime you like.

Run Python 3 & Python 2 without much trouble. Or no need to manually get all Ruby dependencies for a given version.

Example for MacOS

$ brew install rbenv
$ $ rbenv versions                                                                                                                                                                                                              
  system
  2.3.0
* 2.3.6 (set by /Users/<xyz>/.rbenv/version)
  2.6.0
  • Install a new version
$ rbenv install 2.3.6
  • Switch globally to a different version
$ rbenv global 2.3.0

Update the bundler if changing the Ruby version.

gem install bundler

The same commands apply to pyenv.

Internal Working

At a high level, pyenv intercepts Python commands using shim executables injected into your PATH, determines which Python version has been specified by your application, and passes your commands along to the correct Python installation.

Reference

BlinkBlank

Knowledge is the seed of wisdom.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.