It seems ruby needs Unix env in some points. So in windows, we should use wsl to run ruby.
Contents
Enable Windows subsystem for Linux and install Linux
I guess this site has explained very clear. Don’t forget to sudo apt update and upgrade.
Install Ruby/ Ruby On Rails on Windows
Open cmd and type “bash” to turn on wsl.
Then follow all the command line:
4 sudo apt update
5 sudo apt upgrade
8 sudo apt install build-essential
9 sudo apt install git-core curl
10 sudo apt install libssl-dev libyaml-dev
11 sudo apt install libreadline-dev libxml2-dev
12 sudo apt install libsqlite3-dev sqlite3 libffi-dev
20 explorer.exe .
22 sudo apt install zlib1g-dev libxslt1-dev libcurl4-openssl-dev
23 sudo apt install software-properties-common
24 curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash
25 nano .bashrc
27 source .bashrc
28 which rbenv
29 rbenv install --list
30 rbenv install 2.7.3
32 rbenv versions
33 rbenv global 2.7.3
34 rbenv versions
35 ruby -v
36 gem -v
37 gem list
38 gem install rails
39 rbenv rehash
40 rails -v
41 history > print.txt
I have deleted some irrelevant command lines and leave all needed lines. Before line 24, all sudo commands are just installed with all the needed packages.
[Action needed] From line 25 to 28, is going to add the “rbenv” PATH. After opening the .bashrc file, navigate to the end of the file and add 2 lines as below:
export PATH="$HOME/ .rbenv/bin:$PATH"
eval "$(rbenv init -)"
The first line is to set PATH to find the rbenv. And the second line is to tell Linux when it launched go ahead and get ready for the rbenv. After typed these 2 lines, hit “Ctrl + X” and “y” then confirm the file name (no change) by press enter.
source .bashrc is to re-run the file again instead of reboot wsl.
which rbenv is to confirm if the PATH is set or not.
Install MySQL
Use sudo the install MySQL:
sudo apt install mysql-server mysql-client libmysqlclient-dev
Then type “sudo service mysql status” to confirm the installation. If the MySQL is stopped, type “sudo service mysql start” to start it.
Next, we should secure our mysql by the command:
sudo mysql_secure_installation
It would prompt pop a couple questions, except the first question (password validate), all answer “y”.
OK…so the next step is a bit tricky since there is a bug in MySQL. If you tried to use “mysql -u root -p” then enter the password you just made, it won’t work.

We will need to change the config by enter “sudo mysql -u root” then enter typing your sudo password, enter “USE mysql;” Then select data from the user table. “SELECT User, host, plugin FROM user;”

Next, change the root user plugin by the follow query:
UPDATE user SET plugin='mysql_native_password' WHERE user='root';
Then make sure the change has executed by “SELECT User, host, plugin FROM user;”

Finally enter “FLUSH PRIVILEGES;” to let the change effect. Then “quit;” mysql to the Ubuntu and enter “mysql -u root -p” try the mysql password again to see if you can log in.
Install MySQL Ruby gems on Windows
gem install mysql2
Install JavaScript tools for Ruby on Rails
We will need to install node.js, Yarn. Just enter all the command lines as below:
18 gem install mysql2
20 curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
21 sudo apt-get install -y nodejs
22 sudo apt install gcc g++ make
23 curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
24 echo "deb https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
25 sudo apt-get update && sudo apt-get install yarn
Use the webserver on Windows
The common webservers are “Apache 2”, “NGINX (engine-X)” or some minor ones “Passenger”, “Unicorn”, “Puma”. Since Ruby on Rails already build-in with Puma, so for local testing, we are using Puma.
Go to your target folder and simply type “rails new your_project_name -d mysql”