Thursday, April 7, 2022

RAILS INSTALLATION ON WINDOWS (common to WSL)

Windows Subsystem for Linux

INSTALL RUBY

1. Install rbenv

$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc

$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc

$ source ~/.bashrc


2. Install ruby-build

$ mkdir -p "$(rbenv root)"/plugins

$ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build


3. Install the required packages

$ sudo apt -y update && sudo apt -y upgrade

$ cat /etc/issue
Ubuntu 20.04.3 LTS \n \l

[For Ubuntu 20.04 LTS]
$ sudo apt-get install -y gcc make autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev

[For Ubuntu 18.04 LTS]
$ sudo apt-get install -y gcc make autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev libdb-dev


4. Install Ruby using rbenv (it may take 30 minutes to 1 hour to complete depending on the Internet environment).

$ rbenv install 3.0.1


When trying to install Ruby 3.0.1, the following error may occur.

$ rbenv install 3.0.1

ruby-build: definition not found: 3.0.1

See all available versions with `rbenv install --list'.

If the version you need is missing, try upgrading ruby-build:

  git -C /home/user_name/.rbenv/plugins/ruby-build pull

It means that the installedruby-buildcannot install Ruby 3.0.1 because it is an older version.
In this case, you should run the command as instructed (the/home/user_namepart will vary depending on your environment, so replace it accordingly).

$ git -C /home/user_name/.rbenv/plugins/ruby-build pull

After completing the above process, let's install Ruby 3.0.1 again.

$ rbenv install 3.0.1


5. Specify the version of Ruby to be used as standard

$ rbenv global 3.0.1


6. Check the Ruby version

$ ruby -v
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]


INSTALL BUNDLER

$ gem install bundler

$ bundler -v
Bundler version 2.2.26


INSTALL PostgreSQL

$ sudo apt -y install postgresql libpq-dev

$ psql --version
psql (PostgreSQL) 12.6 (Ubuntu 12.6-0ubuntu0.20.04.1)


INSTALL SQLite

$ sudo apt install sqlite3 libsqlite3-dev

$ sqlite3 --version
3.31.1 2020-01-27 19:55:54 3bfa9cc97da10598521b342961df8f5f68c7388fa117345eeb516eaa837balt1


INSTALL RAILS

$ gem install -v 6.0.3 rails

$ rails -v
Rails 6.0.3


Node.js initial Settings

1.  Install nvm
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

2. Pass the path to nvm
$ . ~/.nvm/nvm.sh

3. Check the version of nvm
$ command -v nvm
nvm

4. Install the latest Node.js
$ nvm install --lts
$ nvm use --lts

5. Fixed version
$ nvm alias default lts/*

6. npm update
$ npm update -g npm

7. Check the version
$ node -v
If the version is displayed, then the installation is successful.


INSTALL YARN

$ npm install --global yarn
$ yarn --version
1.22.10
As mentioned above, if the version is displayed, there is no problem.
👌👍😎