In 2023 the answer is similar but different:
Xcode > Preferences
Platforms Tab
Click the lower left hand + button
Select the versions you want to download.
Post
Replies
Boosts
Views
Activity
This article https://wojciechkulik.pl/xcode/xcode-cloud-overview-and-setup suggests putting these lines at the beginning of your script
echo 'export GEM_HOME=$HOME/gems' >>~/.bash_profile
echo 'export PATH=$HOME/gems/bin:$PATH' >>~/.bash_profile
export GEM_HOME=$HOME/gems
export PATH="$GEM_HOME/bin:$PATH"