Around this time last year we soft released our first version of Rivet, a marketplace designed to find and activate resources for the development of creative practices.
Being the tiniest of startups, our entire budget went into this launch. So with no resources to build anything else, I asked our developer, the amazing Francis Tseng, to teach me how to setup a local development environment so that I could a) make copy edits to our html templates and b) try to understand how the system works with the (at the time) far fetched idea that one day I could maintain the product and even build new features.
The first challenge was to get my hands on a Unix based operating system. This meant I either had to setup a Linux distro via a Virtual Machine on my Windows machine, or just wipe the hard drive and go full Linux.
Since I like to do things the hard way, I chose the latter and after many(and i mean many) installs of various linux distros, I've settled, for the moment, with good old Ubuntu and wanted to share with you how to setup a local Rails framework...
So, lets get started on setting up a Ruby on Rails local development environment on a linux machine running Ubuntu 19.04 Disco Dingo:
There may be a need to work with older versions depending on your project, no worries, you'll be able to add them after this initial setup with rbenv(see more below).
First, we need to make sure you have all the dependencies required for both Ruby and Rails.
In your terminal, run:
sudo apt install curl curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn
Install Ruby using the version managing tool called rbenv.
Note you can also use another manager called rvm, but personally I had an easier experience with rbenv.
In your terminal, punch in:
cd git clone https://github.com/rbenv/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc exec $SHELL git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc exec $SHELL rbenv install 2.6.3 rbenv global 2.6.3 ruby -v
The last 3 lines are important here because once you have rbenv setup, you can add other versions of ruby and have the choice to activate/deactivate per your development needs.
The below example will install ruby 2.5.1 and set it as the local version for a specific application you may be working on. Make sure you're in the working folder of your app.
rbenv install 2.5.1 rbenv local 2.5.1
Last but not least, install Bundler so you can package your ruby gems to your hearts content.
gem install bundler
rbenv users need to run
rbenv rehash in your terminal after installing bundler.
For versioning control of your code, we have to setup Git with your account info (for this tutorial, we're using a Github account):
git config --global color.ui true git config --global user.name "YOUR NAME" git config --global user.email "YOUR@EMAIL.com" ssh-keygen -t rsa -b 4096 -C "YOUR@EMAIL.com"
The last step generated a new SSH key for you and your machine. Copy the output of your key from the following command:
and paste it in your Github settings here
Then go back to your terminal to see if it works:
ssh -T firstname.lastname@example.org
You should see:
Hi (username)! You've successfully authenticated, but GitHub does not provide shell access.
gem install rails -v 6.0.0.rc1
Since we are using
rbenv, run the following command to make
rails executable available:
With Rails installed, you can run the
rails -v to check if the version installed installed correctly:
# Rails 6.0.0.rc1
Rails comes with SQLlite out of the box, which is great locally.. but not great if you want to deploy your app to a service like Heroku.
So here are instructions to get PostgreSQL
First we'll need to add a repository to your machine:
sudo apt install postgresql-11 libpq-dev
Next you'll need to setup a user with permissions to create databases locally.
sudo -u postgres createuser username_of_ur_choice -s
You can also (not required) set a password for this user, then:
sudo -u postgres psql postgres=# \password username_of_ur_choice
Lets create your first Rails app!
## Using SQLite rails new myapp ## Using Postgres rails new myapp -d postgresql # Move into the application directory cd myapp # Note - If your Postgres with a username/password, modify the # config/database.yml file in your ruby app folder to include the username/password you defined when setting up postgresql # Create the database rake db:create # Moment of truth rails server
Go to http://localhost:3000 on any browser of your Disco Dingo install to view your locally deployed install of Ruby on Rails!
You should see:
Now that you're up and running, it's time to start building your awesome application/s.