installing ruby version using Rbenv

  1. Install Rbenv: Rbenv is a popular Ruby version manager that allows you to easily switch between different versions of Ruby on your system. To install Rbenv, you can use a package manager like Homebrew (for macOS) or apt-get (for Ubuntu) or follow the instructions specified on the Rbenv GitHub page.

  2. Set up Rbenv: After installing Rbenv, you need to set it up so that it is ready to manage your Ruby versions. This involves adding the necessary initialization code to your shell startup file (e.g., .bashrc or .zshrc). The initialization code typically includes adding the Rbenv bin directory to your PATH and enabling shell integration.

  3. Install Ruby versions: Once Rbenv is set up, you can use it to install different versions of Ruby. Rbenv provides a command called "rbenv install" that allows you to specify the version of Ruby you want to install. For example, you can install Ruby 2.7.3 by running the command "rbenv install 2.7.3".

  4. Set the global Ruby version: After installing multiple Ruby versions, you can set a global default version that will be used by default in new shells. This can be done using the "rbenv global" command followed by the version number. For instance, if you want Ruby 2.7.3 to be the default version, you can run the command "rbenv global 2.7.3".

  5. Set the local Ruby version: In addition to the global default version, you can also set a local version of Ruby for a specific directory. This allows you to have different Ruby versions for different projects. To set a local version, you can use the "rbenv local" command followed by the version number. For example, if you want to use Ruby 3.0.0 for a specific project, navigate to the project directory and run the command "rbenv local 3.0.0".

  6. Verify the Ruby version: Finally, you can verify that the correct Ruby version is being used by running the "ruby -v" command. This will display the installed Ruby version on your system.

By following these steps, you can easily install and manage different versions of Ruby using Rbenv.