Here we discuss Install Ruby on Rails on Windows. For installing Ruby on rails on windows, we will use Bash on Ubuntu in Windows 10 for the reason that it will run Linux on your windows system.
How to install Ruby on Rails in windows 10 ?
You will use both of the worlds i.e. Linux for Ruby on rails purpose and Windows for your day to day work.
NOTE : This will only work for 64-bit installations on your windows system.
Installing Windows Subsystem for Linux on your machine :
For installing Windows subsystem in your machine, we have to know that Windows 10 allows you to use various Linux commands on your machine like a virtual one but it should be implemented natively.
First open Powershell on Windows and run the following command :
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Next install Ubuntu from the Microsoft store : From link provided below https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6
Now open Ubuntu in the Start menu or by running ‘wsl’ in the PowerShell or in the command prompt. You’ll be asked to setup a new user for Ubuntu but remember this password as it’s what you’ll use later on when installing packages with sudo.
You’ve now Ubuntu installed on your machine and we will use it for Rails server and for further process.
Installing Ruby :
We will install Ruby version 3.0.2 which is recommended and best in today’s time. The first step will be to install some dependencies.
sudo apt-get update
sudo apt-get install git-core curl 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
Next we are going to install Ruby using one of three methods and each have their own benefits and advantages, most people prefer using rbenv, but if you are comfortable with rvm you can follow those steps as well. I have included instructions for installing from source as well but generally, you’ll want to choose either rbenv or rvm as per your choice.
We will install using ‘rbenv’ because it’s a simple two step process. First install ‘rbenv’ and then ‘ruby-build’.
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
rbenv install 3.0.2
rbenv global 3.0.2
The installation of ‘rvm’ is simple and can be done by:
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E37D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
rvm install 3.0.2
rvm use 3.0.2 --default
The last step is install Bundler.
gem install bundler
rbenv users need to run rbenv rehash after installing bundler.
Configuring the Git :
We will use Git for version control system so, we will set it and match our Github account. For this you have to make an Github account for you that will be useful for you in future as well.
We can do that by:
Cmd1: git config –global color.ui true
Cmd2: git config –global user.name “YOUR NAME”
Cmd3: git config –global user.email “YOUR@EMAIL.com”
ssh-keygen -t rsa -b 4096 -C “YOUR@EMAIL.com”
You can replace the name and email with yours.
Next, Take the newly generated SSH key and add it to your Github account.
Once it is completed you can check by :
ssh -T firstname.lastname@example.org
If you done all the steps right then , you will see a message like this on your screen:
Hi “Name”! You’ve successfully authenticated, but GitHub does not provide shell access.
We will install Rails for version 188.8.131.52 which is recommended.
To install NodeJS and Yarn, we’re going to use the official repository.
We use following commands:
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 update
sudo apt-get install -y nodejs yarn
And in the end:
gem install rails -v 184.108.40.206
If you’re using rbnev, you have to check run the following command:
Now you’ve install Rails, run ‘ rails-v’ command to chack you have everything installed correctly.
Setting Up MySQL :
You can install MySQL server and client in the Ubuntu repository. You’ll set the password for the root user. This information will feed into Rails app’s ‘database.yml’ file in the future.
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
Setting Up PostgreSQL :
The easiest and effective way to set PostgreSQL in you machine is to install it by windows packager. You will be able to run it on Linux as well.
You will have to install the development header on Ubuntu so you can install the ‘pg gem’.
sudo apt install libpq-dev
Some Final Steps:
And also The best place to develop Rails the Windows is to navigate to
/mnt/c that is subsystem for Linux. This is actually the C: drive on Windows and it will let you use Atom, Sublime, VS Code on Windows to edit your Rails applications.
Now, you have to run the following commands :
Create a code directory at C:\code for your Rails apps to live
mkdir -p code
Note this will expect a postgres user with the same username
as your app, you may need to edit config/database.yml to match the
rails new myapp -d postgresql
or if you want to use SQLite
rails new myapp
Or if you want to use MySQL
rails new myapp -d mysql
Then move it into application directory
If you setup MySQL or Postgres with a username/password, modify the
config/database.yml file to contain the username/password that you specified
Create the database
rake db:create rails server
Firstly, To edit your code in windows : open up Sublime, Atom, VS Code, or whatever editor your prefer and point them to your folders in C:\code and you’ll be able to safely edit your Rails apps in Windows and run them in Linux.
When you create a new Rails app, you may run into the following error: parent directory is world writable but not sticky.
If you run into this issue, you can run chmod +t -R ~/.bundle and that should fix the permissions errors and let you finish the bundle install for your Rails app.
Related Articles: Install Ruby on Rails on Windows
- Benefits of Using Angular for Web Development 2021
- Difference Between C vs C++ vs Python vs Java
- KALI Linux Not Prefer Software Development Ubuntu
- Angular 12 Performance Benchmark Install Features
- Setup Angular 12 vs 11 vs 10 features benchmark
- How to Write Business Proposal for Client with Sample Format
- Top 10 Best Coolest Movies Chris Hemsworth of all time
- How to install wordpres on local machine like window 10 linux and Mac – Click here
- C vs C++ Difference Between C vs C++ vs Python vs Java
- Who is the strongest character in Naruto
- Top 10 Penny Stocks Invest 2021 Higher Return in 2025 2030