rubyonrails
Install Ruby On Rails on Windows 10
This only works on 64-bit installations of Windows. This is also in beta, so this won't be nearly as robust as running a Linux virtual machine, but it can definitely do the basics well enough.
Installing the Windows Subsystem for Linux
Windows 10 allows you to run various Linux operating systems inside of Windows similar to a virtual machine, but natively implemented. We'll use this to install Ruby and run our Rails apps.
Open Powershell as Administrator and run:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Now open Ubuntu in the Start menu or by running wsl in PowerShell or the command prompt. You'll be asked to setup a new user for Ubuntu. Remember this password as it's what you'll use later on when installing packages with sudo.
Congrats! You've now got a Ubuntu terminal on Windows. You'll use this to run your Rails server and other processes for development.
Installing Ruby.
Go to rubyinstaller to install ruby for window 10
We recommended the last version of Ruby.
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're going to be installing Ruby using 'rbenv '
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 3.0.1
rbenv global 3.0.1
ruby -v
Arguably the least useful Ruby setup for development is installing from source, but I thought I'd give you the steps anyways:
cd
wget http://ftp.ruby-lang.org/pub/ruby/3.0/ruby-3.0.1.tar.gz
tar -xzvf ruby-3.0.1.tar.gz
cd ruby-3.0.1/
./configure
make
sudo make install
ruby -v
Installing with rbenv is a simple two step process. First you install rbenv, and then ruby-build:
The installation for rvm :
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 3.0.1
rvm use 3.0.1 --default
ruby -v
The last step is to install Bundler
gem install bundler
Installing Rails
Recommended to install the last version of rails.
to get the last rails version here. or as shown below:
GEMFILE:
gem 'rails', '~> 6.1', '>= 6.1.3.2'
INSTALL:
gem install rails
gem install rails
Setting Up PostgreSQL
sudo apt install libpq-dev
Final Steps
The best place to develop Rails apps on the Windows Subsystem for Linux is to navigate to `/mnt/c`. This is actually the C: drive on Windows and it lets you use Sublime, Atom, VS Code, etc on Windows to edit your Rails application.
And now for the moment of truth. Let's create your first Rails application:
# Navigate to the C: drive on Windows. Do this every time you open the Linux console.
cd /mnt/c
# Create a code directory at C:\code for your Rails apps to live (You only need to do this once)
mkdir -p code
#### If you want to use Postgres
# Note that this will expect a postgres user with the same username
# as your app, you may need to edit config/database.yml to match the
# user you created earlier
rails new myapp -d postgresql
#### or if you want to use SQLite (not recommended)
# rails new myapp
#### Or if you want to use MySQL
# rails new myapp -d mysql
# Then, move into the application directory
cd myapp
# 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
Now visit http://localhost:3000 to view your new website!
Now that you've got your machine setup, it's time to start building some Rails applications!
If you received an error that said Access denied for user 'root'@'localhost' (using password: NO) then you need to update your config/database.yml file to match the database username and password.