In this post let’s setup Ruby and ruby gemsets for each project, so that your package versions are maintained.
Install ruby-build # ruby-build is a command-line utility for rbenv
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build # Add ruby build path echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc # OR echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.zshrc # load it source ~/.bashrc # OR source ~/.zshrc
For Mac users – iOS users
# verify rbenv curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash If you are using zsh add the following to `~/.zshrc` # rbenv configuration eval "$(rbenv init -)" export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix firstname.lastname@example.org)"
Install Ruby 2.5.1 using rbenv
rbenv install 2.5.1 rbenv global 2.5.1 # to make this version as default ruby -v # must display 2.5.1 if installed correctly which ruby # must show the fully qualified path of the executable echo "gem: --no-document" > ~/.gemrc # to skip documentation while installing gem rbenv rehash # latest version of rbenv apparently don't need this. Nevertheless, lets use it to avoid surprises. gem env home # See related details # If a new version of ruby was installed, ensure RubyGems is up to date. gem update --system --no-document
Install rbenv gemset – https://github.com/jf/rbenv-gemset
git clone git://github.com/jf/rbenv-gemset.git ~/.rbenv/plugins/rbenv-gemset
If you are getting following issue:
fatal: remote error: The unauthenticated git protocol on port 9418 is no longer supported. # Fix git clone https://github.com/jf/rbenv-gemset.git ~/.rbenv/plugins/rbenv-gemset
Now clone your project and go inside the project folder -Micro-service folder (say my-project) which has Gemfile in it and do the following commands.
cd my-project my-project $ rbenv gemset init # NOTE: this will create the gemset under the current ruby version. my-project $ rbenv gemset list # list all gemsets my-project $ rbenv gemset active # check this in project folder my-project $ gem install bundler -v '1.6.0' my-project $ rbenv rehash my-project $ bundle install # install all the gems for the project inside the gemset. my-project $ rails s -e production # start rails server my-project $ puma -e production -p 3002 -C config/puma.rb # OR start puma server # OR start the server you have configured with rails.
Do this for all the services and see how this is running. The above will install all the gems inside the project gemset that acts like a namespace.
So our aim is to setup all the
ruby micro-services in the same machine.
- I started 10 services together in AWS EC2 (type: t3.small).
- Database is running in t2.small instance with 2 volumes (EBS) attached.
- For Background job DB (redis) is running in t2.micro instance.
So for 3 ec2 instance + 2 EBS volumes –
elastic IP addresses ( aws charges some amount –
$7.4) 1 month duration, it costs me around
$77.8, almost 6k rupees. That means we reduced the aws-cloud cost to half of the previous cost.