Intro
Here's a quick setup for ruby development on a Linux machine. It has been tested in Ubuntu 20.04 native, Ubuntu 22.04 on WSL 2 and Debian Bullseye. It should be able to execute smoothly as a standalone script, but it is recommended to run in parts so if something goes wrong it won't break the rest.
It is almost unopinionated except for the version manager choice (the lightweight rbenv over rvm) and local documentation policy (rdoc should not be downloaded automatically for all gems).
# Part One: Install basics
# zlib1g-dev might be zlib-dev on Ubuntu 22.04
# lsb-release might be lsb_release on Ubuntu 22.04
sudo apt-get update && sudo apt-get -y install \
git \
ca-certificates \
curl \
gnupg \
build-essential \
lsb-release \
zlib1g-dev \
libssl-dev \
zsh && \
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# Part Two: Installs & sets up rbenv, installs ruby
git clone https://github.com/rbenv/rbenv.git ~/.rbenv && \
echo 'eval "$(~/.rbenv/bin/rbenv init - zsh)"' >> ~/.zshrc && \
source ~/.zshrc && \
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build && \
rbenv install 3.1.2 && \
rbenv global 3.1.2
# Part Three: Optional minimum setup for Rails development
echo "gem: --no-document" >> ~/.gemrc && \
gem install bundler && \
gem install rails
Explanation
Part One: Install basics
Here we're installing not only the base libraries needed to run rbenv & ruby-build (the rbenv plugin that will actually install Ruby), but also ZShell and its famous extension, oh-my-zsh. This offers some nice things such as syntax & branch highlighting, and it is completely optional. If you'd like to keep your bash as it is, just skip this step (however, note you'll have to add rbenv to their bash correspondent instead of zshell init files!).
Part Two: Installs & sets up rbenv, installs ruby
This downloads rbenv into a hidden folder within the current user space, adds rbenv initialization to the shell's initialization script and then downloads the ruby-build plugin, which enables direct download & installation of ruby versions directly from rbenv; then it installs a ruby version (3.1.2 is the most recent by the time this is being written) and sets it up as the global version for the system. You can also set a local version for each project with rbenv local <version_number>
.
Part Three: Optional minimum setup for Rails development
Finally, this will add a flag to not download gem documentation alongside gems. If you need documentation on a specific gem, check RubyDoc instead; this saves a surprising amount of time and space. You'll finally install bundler and rails. If you've ever done this process before, I'm sure you'll notice how quicker it gets without the extra overhead for documentation, or I'll give your money back!
Top comments (1)
This post is important information shared to useful for programming. dua to make the impossible happen