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.

How to set up your Linux Environment – Part I

So I am a software engineering student at Flatiron School, and unfortunately we had to go remote due to the COVID-19. For the SE program full immersive on campus course they require you to use a Mac. Not a huge fan. So I had to rent a macbook air which wasnt bad for the purposes. Until we went remote. The overpriced hunk of junk was overheating and running ridiculously slow while in Zoom meetings, sharing screens, coding, etc.

I wanted to use my beast of a laptop for this program from the beginning but I knew that I had to set up a Linux environment. So here is how I went about doing that…

First off there are two ways you can do this. You can either Dual Boot Linux onto your windows(or mac -_-) or you can set up a virtual machine. I have tried both ways and I prefer the Dual Boot. That is what I will be going over today. Also I am using windows to dual boot.

Step 1

So you will need a usb flash drive that is > 25GB. We will be using this to make a bootable drive that will have Ubuntu 18.04 (linux) installed on it. You can download the latest version from here. Once that is downloaded and you have your USB drive you can download the Rufus tool to easily set up Ubuntu to be Bootable from your flash drive. You can get the tool and read how to use it (pretty self explanatory) here.

Step 2

Before going any further you can backup your current drive however this is widely tested and most people don’t have problems. Now you need to disable fast boot on your windows. You can do this by going to Power Options > System Settings > Choose what the power buttons do and uncheck the Turn on fast startup box.

Now we need to disable Secure Boot. If this sounds unfamiliar and risky to you, don’t worry its completely safe and is necessary for booting from the FLASH drive with ease.

So in order to do this in your search bar search “Advanced Startup Options”. You will want to select Restart Now and from there Select Troubleshoot>Advanced Options>UEFI Firmware Option Settings>Restart. You computer will restart and take you to the BIOS settings. Go to the Boot Tab and from there you disable Secure Boot.

You can now restart and log back into windows.

Step 3

We need to create HardDrive space for Linux. We are going to set aside a portion of the computers hard drive for this. Using the search bar, look up “Create and Format Hard Disk Partitions”.

You can select the partition that you want to set aside space from and you can click “Shrink Partition” and you can set how much space you want for Linux. I recommend at least 25GB but I put aside 100GB myself since it is where I will be doing all of my future projects. You will see Free Space in green once with the amount that you specified.

Now we are ready to boot up from our flash drive we made earlier with Ubuntu and install it on our computer. First we need to restart again and go into or BIOS settings to enable boot from flash drive. You can access the BIOS in a few different ways, it depends on your computer, but the most common way is to hit F12 or ESC or F2 at the start up of the computer.

You will see your BIOS Menu, go over to boot, and you should see your USB (it should be plugged in…) as a boot option. The menu looks like the image below.

Step 4 – Installation

Now it will boot from your flash drive and it will restart. It might sit on a black screen for a second but it will load up the Ubuntu Installation screen and will look like so…

You will want to choose Install Ubuntu with your preferred language and it will take you to the next menu. You will be asked to choose your keyboard layout, it is default to the U.S. layout but there is a list you can choose from. From there it will take you to the Installation Type.

Here if the option shows up for Install Ubuntu alongside windows 10, choose this option. This will make the installation very easy and most everything is done for you. You will just have to choose the partitioned memory that we set up early for the installation.

If it does not show up choose something else, and I will walk you through the steps. DO NOT choose Erase Disk and Install Ubuntu! If you do this you will erase the windows on your computer and you will only have Ubuntu OS on your computer. If you accidentally did choose this… lets hope you set up a back up or bye bye windows..

Now if you chose “Something Else” follow the next steps carefully. You will come to a screen where you will choose the partition of memory that you set up earlier. It will say “free space”. Something like this picture below…

Select the free space and then you’re going to want to select the “+” button. This will let us set up the Swap Area. The swap area is basically virtual memory. So if you computer ever runs out of memory or RAM, Ubuntu will use this extra memory set aside to help out. Once you click the “+” you will get a menu and you will want to put in an option of how much memory you want to set aside for the swap area. The general rule of thumb is to set aside 1x-2x of the amount of RAM that your computer has. So if you running 8bg of RAM you can put between 8-16GB aside for the swap area.

After you put in the size, remember 1000mb = 1gb, you want to make sure to choose “Logical”, “Beginning of this space” and on the drop down menu choose swap area. Then click ok. Next we will repeat this process but for setting up the rest of the allocated memory for the hard drive. So now your going to want to select the free space again and click the “+” button. You will get the same menu but you want to leave the “size:” at what it is at, because that is the remaining space after allocating your swap area. Choose “logical”, “Beginning of space”, and on the drop down menu select “Ext4 journaling file system”. For the mount point, select “/”; this is your Root directory.

Click ok and then you can go ahead and click “install now”. A menu will come up, double check to make sure you’re installing to the correct drive and then click “Continue”.

You will come to a screen to select your location, so go ahead and choose the time zone that you’re in. At this point you will come to a menu to custimize the name of your computer and set up your password. It will finish, and you will have to restart your computer. At this point, remove the USB so it wont boot from the USB. When it restarts it will come to the GNU GRUB interface menu. You can choose which OS to jump into. It will be Ubuntu on the top but you can always go down and select windows.

Now you’re ready to use Ubuntu! You will go through some “how-to” menus but you can skip all of that. Now we can get into the fun part. Lets set up your programming environment. Click the link to part 2 of this post to see how.

Continue setup with Part 2 here.

Also here is a YouTube resource for setting up Ubuntu in case you need a visual representation. I used this when first learning how to do this…