rbenv (with examples)
1: Install a Ruby version
rbenv install version
Motivation: This command is used to install a specific Ruby version on your system. By installing different versions of Ruby, you can choose the one that is compatible with your application’s requirements.
Explanation: Replace “version” in the command with the specific version number or name of the Ruby version you want to install. For example, to install Ruby version 2.7.1, you would use rbenv install 2.7.1
.
Example Output: The output will show the progress of the installation process and indicate when the installation is complete.
2: Display a list of the latest stable versions for each Ruby
rbenv install --list
Motivation: This command allows you to see a list of the latest stable versions of Ruby available for installation. It helps you determine which versions are currently supported and choose the most suitable one for your application.
Explanation: Simply enter rbenv install --list
to display the list of available Ruby versions.
Example Output: The output will show a list of the available Ruby versions, with the latest stable versions highlighted.
3: Display a list of installed Ruby versions
rbenv versions
Motivation: This command allows you to see a list of Ruby versions that are already installed on your system. It helps you keep track of the installed versions and manage them effectively.
Explanation: Enter rbenv versions
to display a list of all installed Ruby versions.
Example Output: The output will show the installed Ruby versions, indicating the currently active version with an asterisk (*) and marking non-active versions with a space.
4: Use a specific Ruby version across the whole system
rbenv global version
Motivation: Sometimes it’s necessary to set a specific Ruby version as the default across your entire system. This command allows you to do that, ensuring consistency across different applications and projects.
Explanation: Replace “version” in the command with the specific Ruby version you want to set as the global version. For example, rbenv global 2.7.1
sets Ruby version 2.7.1 as the global version.
Example Output: There will be no output if the command is successful. To verify the change, you can use the rbenv version
command.
5: Use a specific Ruby version for an application/project directory
rbenv local version
Motivation: Different applications or projects may require different Ruby versions. By using this command, you can specify a Ruby version for a specific directory, ensuring that the correct version is used when working on that project.
Explanation: Replace “version” in the command with the specific Ruby version you want to set as the local version. For example, rbenv local 2.7.1
sets Ruby version 2.7.1 as the local version for the current directory.
Example Output: There will be no output if the command is successful. To verify the change, you can use the rbenv version
command.
6: Display the currently selected Ruby version
rbenv version
Motivation: It is useful to be able to view the currently selected Ruby version, especially when working on multiple projects that require different Ruby versions. This command allows you to check the active Ruby version.
Explanation: Simply enter rbenv version
to display the currently selected Ruby version.
Example Output: The output will show the currently active Ruby version with an asterisk (*) next to it.
7: Uninstall a Ruby version
rbenv uninstall version
Motivation: If you no longer need a specific Ruby version on your system, you can uninstall it to free up space and simplify your Ruby environment. This command allows you to remove an installed Ruby version.
Explanation: Replace “version” in the command with the specific Ruby version you want to uninstall. For example, rbenv uninstall 2.7.1
uninstalls Ruby version 2.7.1.
Example Output: The output will show the progress of the uninstallation process and indicate when the uninstallation is complete.
8: Display all Ruby versions that contain the specified executable
rbenv whence executable
Motivation: If you’re unsure which Ruby versions on your system contain a specific executable, you can use this command to find out. It helps you determine which Ruby versions have the necessary dependencies for your application.
Explanation: Replace “executable” in the command with the name of the executable you want to check. For example, rbenv whence ruby
would display all Ruby versions that contain the “ruby” executable.
Example Output: The output will show a list of Ruby versions that contain the specified executable.