Bird
Raised Fist0
Rubyprogramming~20 mins

Ruby version management (rbenv, rvm) - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Ruby Version Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
1:30remaining
What is the output of this rbenv command?
You run the command rbenv versions after installing Ruby 3.1.2 and 2.7.6. What output will you see?
Ruby
$ rbenv versions
  system
* 3.1.2 (set by /home/user/.rbenv/version)
  2.7.6
A
  system
* 3.1.2 (set by /home/user/.rbenv/version)
  2.7.6
B
* 3.1.2
  2.7.6
  system
C
3.1.2
2.7.6
system
DNo versions installed
Attempts:
2 left
💡 Hint
The asterisk (*) marks the currently active Ruby version.
❓ Predict Output
intermediate
1:30remaining
What happens when you run rvm use 2.6.5 if Ruby 2.6.5 is not installed?
You run rvm use 2.6.5 but Ruby 2.6.5 is not installed on your system. What will be the result?
Ruby
rvm use 2.6.5
ARVM will uninstall all Ruby versions.
BRVM will automatically download and install Ruby 2.6.5, then switch to it.
CRVM will switch to the system Ruby version instead.
DRVM will show an error: 'Unknown ruby interpreter or version: 2.6.5'.
Attempts:
2 left
💡 Hint
The plain `rvm use` command requires the version to be installed first; use `rvm install` separately.
🔧 Debug
advanced
2:00remaining
Why does ruby -v show a different version than rbenv version?
You set Ruby 3.0.0 as global with rbenv global 3.0.0, but running ruby -v shows Ruby 2.7.0. What is the most likely cause?
AYour shell environment does not have <code>rbenv</code> initialized in PATH.
BYou forgot to run <code>rbenv rehash</code> after installing Ruby 3.0.0.
CRuby 3.0.0 is not installed at all.
DYou need to uninstall Ruby 2.7.0 manually.
Attempts:
2 left
💡 Hint
Check if rbenv commands are recognized and PATH is set correctly.
📝 Syntax
advanced
1:30remaining
Which command correctly sets a local Ruby version with rbenv?
You want to set Ruby 3.2.0 only for the current project directory. Which command is correct?
Arbenv use 3.2.0
Brbenv global 3.2.0
Crbenv local 3.2.0
Drbenv set 3.2.0
Attempts:
2 left
💡 Hint
Local version affects only the current directory and subdirectories.
🚀 Application
expert
2:30remaining
How to ensure a Ruby script uses a specific Ruby version with rvm in a CI pipeline?
You want your CI pipeline to run a Ruby script using Ruby 2.7.4 managed by RVM, without affecting other jobs. Which is the best approach?
AInstall Ruby 2.7.4 globally on the CI machine and run the script directly.
BAdd <code>rvm use 2.7.4 --install --binary --fuzzy</code> before running the script.
CUse <code>rbenv local 2.7.4</code> in the CI script before running Ruby.
DSet the environment variable <code>RUBY_VERSION=2.7.4</code> and run the script.
Attempts:
2 left
💡 Hint
RVM can install and switch Ruby versions on the fly in scripts.

Practice

(1/5)
1. What is the main purpose of using Ruby version managers like rbenv or rvm?
easy
A. To debug Ruby code automatically
B. To write Ruby code faster
C. To compile Ruby programs into executables
D. To switch between different Ruby versions easily

Solution

  1. Step 1: Understand Ruby version managers

    Ruby version managers like rbenv and rvm allow you to install and switch between multiple Ruby versions on the same machine.
  2. Step 2: Identify the main use

    The main use is to switch Ruby versions easily without affecting other projects or the system Ruby.
  3. Final Answer:

    To switch between different Ruby versions easily -> Option D
  4. Quick Check:

    Ruby version managers help switch versions = D [OK]
Hint: Remember: rbenv and rvm manage Ruby versions [OK]
Common Mistakes:
  • Thinking they speed up coding
  • Confusing with debugging tools
  • Assuming they compile Ruby code
2. Which of the following commands correctly sets the global Ruby version to 3.1.2 using rbenv?
easy
A. rbenv global 3.1.2
B. rbenv use 3.1.2
C. rbenv set 3.1.2
D. rbenv switch 3.1.2

Solution

  1. Step 1: Recall rbenv commands

    The command to set the global Ruby version in rbenv is rbenv global <version>.
  2. Step 2: Match the correct command

    Among the options, only rbenv global 3.1.2 correctly sets the global version.
  3. Final Answer:

    rbenv global 3.1.2 -> Option A
  4. Quick Check:

    Set global version = rbenv global [OK]
Hint: Use 'rbenv global' to set Ruby version globally [OK]
Common Mistakes:
  • Using 'rbenv use' which is invalid
  • Confusing 'set' or 'switch' commands
  • Not specifying the version number
3. Given the following commands run in order:
rbenv install 3.0.0
rbenv local 3.0.0
ruby -v
What will be the output of ruby -v?
medium
A. ruby 2.7.0 (system default)
B. Command not found error
C. ruby 3.0.0 (installed version)
D. ruby 3.1.0 (latest version)

Solution

  1. Step 1: Understand the commands

    rbenv install 3.0.0 installs Ruby 3.0.0. rbenv local 3.0.0 sets the Ruby version to 3.0.0 for the current directory.
  2. Step 2: Predict the ruby version output

    Running ruby -v in that directory will use Ruby 3.0.0, showing its version.
  3. Final Answer:

    ruby 3.0.0 (installed version) -> Option C
  4. Quick Check:

    Local version set to 3.0.0 means ruby -v shows 3.0.0 [OK]
Hint: Local version overrides system Ruby version [OK]
Common Mistakes:
  • Assuming system default Ruby is used
  • Expecting latest Ruby version output
  • Thinking command will fail without global set
4. You run rvm use 2.7.0 but get the error: RVM is not a function, selecting rubies with 'rvm use ...' will not work.
What is the most likely cause?
medium
A. RVM is not installed
B. You did not load RVM as a shell function
C. Ruby 2.7.0 is not installed
D. You need to restart your computer

Solution

  1. Step 1: Understand the error message

    The error says 'RVM is not a function', which means the shell does not recognize RVM commands properly.
  2. Step 2: Identify cause

    This usually happens if the RVM script is not sourced in the shell, so RVM commands are not loaded as functions.
  3. Final Answer:

    You did not load RVM as a shell function -> Option B
  4. Quick Check:

    Load RVM script in shell to fix 'not a function' error [OK]
Hint: Always source RVM script in your shell config [OK]
Common Mistakes:
  • Assuming RVM is not installed at all
  • Thinking Ruby version is missing
  • Restarting computer unnecessarily
5. You want to create a project that uses Ruby 3.2.0 but your system default is Ruby 2.6.3. Using rbenv, which sequence of commands correctly sets up your project to use Ruby 3.2.0 locally without affecting other projects?
hard
A. rbenv install 3.2.0
rbenv local 3.2.0
B. rbenv local 3.2.0
rbenv install 3.2.0
C. rbenv install 3.2.0
rbenv global 3.2.0
D. rbenv global 3.2.0
rbenv install 3.2.0

Solution

  1. Step 1: Install Ruby 3.2.0 first

    You must install Ruby 3.2.0 before using it. So rbenv install 3.2.0 is first.
  2. Step 2: Set local version for project

    To use Ruby 3.2.0 only in the project folder, use rbenv local 3.2.0. This does not affect other projects or the global version.
  3. Final Answer:

    rbenv install 3.2.0
    rbenv local 3.2.0
    -> Option A
  4. Quick Check:

    Install then set local version for project isolation [OK]
Hint: Install Ruby first, then set local version for project [OK]
Common Mistakes:
  • Setting global version instead of local
  • Setting local version before installing Ruby
  • Assuming global affects only one project
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard