HOW TO SET UP YOUR LINUX ENVIRONMENT – PART II (Learn.co Setup Included)

So now you have your Ubuntu installed and you’re ready to move forward and set up your Coding Environment. We will go through the process of getting a good IDE as well as installing all of the packages that we need. I’ll also take you through the steps of setting up your Linux to interface with Learn.co in case you are a student with the Flatiron School. Lets get started…

First off we need to set up a “Group” that we will name “npm”. This way we can set permissions on packages that get installed via npm. This will allow us to globally install npm packages. Copy and paste both of these commands into your terminal.

sudo groupadd npm
sudo usermod -a -G npm,staff $USER

Lets go ahead and make sure that our system is up to date before moving forward. You can do this by using the following code in your terminal…

sudo apt update
sudo apt upgrade

Essentials Dev Tools

Ok now that we are up to date lets install some of the essentials. (Most of this guide will be simply pasting code into your command line.) So the following code will install Node.js, sqlite3, and Postgres. You will need Postgres for when you hit the limits of sqlite3. If you don’t know what these are for yet, don’t worry you will learn what they are eventually.

sudo apt-get -y install curl postgresql libpq-dev default-jre build-essential phantomjs
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install nodejs

File Permissions

Now that we have that set up lets set up some file permissions, that way we will be able to properly use the tools that we just installed through the terminal.

sudo chown root:staff /usr/bin
sudo chmod 0775 /usr/bin
sudo chown -R root:npm /usr/lib/node_modules
sudo chmod 0775 /usr/lib/node_modules

chmod stands for “Change Command”, and chown stands for “Change Owner”. You can read more about these commands, and what they do, here if you would like. Ok moving on.

Necessary for Learn.co (Flatiron Students only)

This next command is for Flatiron Students specifically, so if you are not enrolled then you can ignore this next command. So at the Flatiron school they have learning system set up that they call Learn.co and it has predefined commands called “learn”. You will need to use this frequently while doing your labs. In order for the learn gem to work we need a netrc file. The .netrc file is a standard location to store login/token info, so that is where we store information needed for learn.

touch ~/.netrc && chmod 0600 ~/.netrc

Touch is a command used to create a file and we just went over what chmod stands for earlier.

Installing RVM (Ruby Version Manager)

Ok next lets install RVM. Rvm is a tool that we use to specify or change the version of Ruby on our computer. Some of the labs will require you to use older versions of Ruby so this will come in handy later if you’re a student at Flatiron. Also, in the future you could be working on a project that was previously done in an older version of Ruby, RVM allows you to change to whatever version you need. You can install it by putting in the following commands, in order.

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

\curl -sSL https://get.rvm.io | bash

echo "[[ -s "$HOME/.rvm/scripts/rvm" ]]" && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*"

rvm install 2.6.1

rvm use 2.6.1 --default

So using rvm install <version> you can install the version that you need, and use rvm use <version> to switch between different versions that you have installed. You can check to see what versions have been install using the command rvm list, and check the current active version using ruby -v.

Setting up Ruby Gems

If you are not yet familiar with a programming language, in Ruby, Gems are basically libraries of code. You can install these and add these chunks of code to your projects, and it can make your life a lot easier. Learn from Learn.co is one of these Gems. Lets set this up now.

echo "gem: --no-ri --no-rdoc" > $HOME/.gemrc
gem update --system
gem install learn-co
gem install phantomjs
gem install pg
gem install sqlite3
gem install bundler
gem install rails

These Gems are just the basics to get you started. You will find more that you like or that you need as you learn and start new projects.

Installing Node Package

Similar to Gems there is NPM, or Node Package Manager. Again, these are just chunks of code that you can install and use in your projects. We need to install NPM as well as NVM (Node Version Manager).

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
restart your terminal after imputing the above code, then enter the below code...
verify NVM was install properly by typing... nvm --version
you should get an output of a version such as '0.34.0'

Now run the following code in your terminal to finish up the installation.

nvm install node
node --version

nvm install --lts
nvm install 8.10.0

nvm ls   (this will display a list of all the versions you have installed)

Set up your Github account on your Computer

If you have not set up a Github account already, then before you proceed you need to go to github and set up and account. All of your projects will be stored on your github and you will be pulling and pushing files to and from your Github repositories. So we need to link your account to your pc. You need to set up and SSH key for you computer so you don’t have to put in a password every time you want to send data to your github account.

ssh-keygen

(Only generate an SSH key if you don’t already have a generated SSH key. Just press enter for everything and don’t enter a password.)

cat ~/.ssh/id_rsa.pub

This will display your SSH Key in your terminal. Copy your key and then add the key to your github account. You can do this by following their instructions here.

Finish Learn.co configuration

Ok so we have most of what we need to have a legit Dev environment. Again, learn is for Faltiron students, so you can skip over this if you are not enrolled. We have to link your Learn.co account with your github. You will be doing labs, running tests, submitting code, and all of this gets pushed to your github which Learn can see.

learn whoami

Enter OAuth token when asked…

  • If you have connected your Github account to your Learn account, navigate to learn.co/your_github_username. The OAuth token is at the bottom of the page.
  • If you have not connected your Github account: Go to your profile > Learn Settings > Public Profile. Click on the link under Username. The OAuth token is at the bottom of the page.

You’re now set up for Learn.co. However, even though there is a built in IDE to Learn.co it does not work on Linux OS. So we need to do all of your labs in an IDE installed on your computer. MAC users will eventually start doing this, and it is recommended that you do this as soon as possible anyways. You can find instructions on how to open labs in your Text Editor here.

Download Useful Apps

If you don’t already have an IDE installed on your computer you need one. I would highly recommend VSCode, especially for beginners, but it is your personal preference. I will post links to VSCode download and other good apps to have in your Dev environment below.

Visual Studio Code

Download here

Google Chrome

Download here

Slack for Linux

Download here

Zoom (Essential if you happen to face a pandemic…)

Download here

Spotify (because we all need some music in our lives)

There is not currently a download client for linux, so we will have to install via the terminal. Copy and paste the below all at once.

curl -sS https://download.spotify.com/debian/pubkey.gpg | sudo apt-key add - 
echo "deb http://repository.spotify.com stable non-free" | sudo tee /etc/apt/sources.list.d/spotify.list

This configured their Debian repository. Now we can install the spotify client.

sudo apt-get update && sudo apt-get install spotify-client

Now we have some tunes!

Optional Files

Alright you are pretty much done and can get to coding! There are some more helpful files that we can install to make our lives easier and I would recommend it, but it is not necessary.

curl "https://raw.githubusercontent.com/flatiron-school/dotfiles/master/irbrc" -o "$HOME/.irbrc"

This file gives you some nice formatting for when you’re in IRB (IRB lets you write ruby code in your terminal)

curl "https://raw.githubusercontent.com/flatiron-school/dotfiles/master/ubuntu-gitignore" -o "$HOME/.gitignore"

Global .gitignore rules. When you add a .gitignore file to a project, it let’s you specify certain files that you DO NOT want pushed up to github (like API keys…)

curl "https://raw.githubusercontent.com/flatiron-school/dotfiles/master/linux_bash_profile" -o "$HOME/.bash_profile"

Your bash profile loads up every time you open a terminal window. The Learn bash_profile is designed to load up a bunch of shortcuts for you as well as make sure that RVM loads up every time you open the terminal. I recommend you take a look at this file and even see if there are any shortcuts of your own that you’d like to add! Note: this will overwrite existing bash profile, so back up if you want to.

curl "https://raw.githubusercontent.com/flatiron-school/dotfiles/master/linux_gitconfig" -o "$HOME/.gitconfig"

nano $HOME/.gitconfig

With this you can edit github username and github email in a few places.

AND THATS IT! You are good to go.

One thought on “HOW TO SET UP YOUR LINUX ENVIRONMENT – PART II (Learn.co Setup Included)

Leave a comment