Update brew first, the terminal executes the following commands
brew update
Then update ruby, the terminal executes the following commands
brew install ruby
After the update is successful, ruby uses the old version by default
Check the version, the terminal executes the following commands
ruby -v
Specify the path, configure environment variables
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
or
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
💡💡💡 notes💡💡💡
1) Both .bash_profile and .zshrc are in the user's root directory, namely (~);
2) .bash_profile can be created manually .zshrc needs to be created by installing oh-my-zsh, manual creation does not take effect;
3). Bash_profile modify environment variables, only valid for the current window, and need to execute'source ~/.bash_profile' to take effect;
4) The computer will execute the .zshrc file by default;
5) You can inject'source .bash_profile' into the .zshrc file, once and for all;
Check the version again and verify the current version number
ruby -v
Install rvm, the terminal executes the following commands
\curl -sSL https://get.rvm.io | bash -s stable --ruby
View rvm version
rvm -v
View the list of installable ruby versions
rvm list known
Install the specified ruby version (such as 3.0.2
)
rvm install ruby-3.0.2
View the current ruby version
which rvm
Set the default ruby version (such as 3.0.2)
rvm --default use 3.0.2
Use the specified ruby version (such as 2.6.3)
rvm use ruby-2.6.3
Uninstall the specified ruby version (such as 2.6.3
)
rvm remove 2.6.3