Technically Impossible

Lets look at the weak link in your statement. Anything "Technically Impossible" basically means we haven't figured out how yet.

Rails on WSL2 + Ubuntu 20.04 LTS - Error-free installation process with minimum packages

f:id:espio999:20210428115001p:plain

Abstract

This article introduces the installation process of Ruby on Rails. Basic process is

  1. Install packages
  2. Install Gems
  3. New Rails project and run server for operation check

The characteristic part is Yarn installation. It is installed with "npm", not "apt". This reason is also explained in the guidance.

Prerequisite

Use Ubuntu 20.04 LTS provided in Microsoft Store. In advance of Rails installation, apt packages should be updated by commands below.

sudo apt update
sudo apt upgrade

This installation process doesn't set certain version in commands. At 2021-04-28, following versions are installed.

wsluser@paulownia:~$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
wsluser@paulownia:~$ rails -v
Rails 6.1.3.1
wsluser@paulownia:~$ sqlite3 --version
3.31.1 2020-01-27 19:55:54 3bfa9cc97da10598521b342961df8f5f68c7388fa117345eeb516eaa837balt1
wsluser@paulownia:~$ node --version
v10.19.0
wsluser@paulownia:~$ yarn --version
1.22.10

Packages

Next packages are installed following the official guidance.
guides.rubyonrails.org

Package
Ruby ruby-full
SQLite3 sqlite3
Node.js nodejs
Yarn

Install Yarn separately. Its reason is explained later.

Dependencies

Package
build-essential Build environment
libsqlite3-dev SQLite3 libraries
npm Package manager
Used for Yarn installation

Installation process

Package installation

Install Ubuntu packages with "apt"

sudo apt install ruby-full sqlite3 nodejs build-essential libsqlite3-dev npm
Yarn installation

Node.js uses "npm" as its package manager, and Yarn is installed with it.
The package "npm" is suggested at Ubuntu packages below.
Ubuntu – Details of package nodejs in focal

And it is recommended that Yarn should be installed with "npm", according to the official Yarn site.

It is recommended to install Yarn through the npm package manager, which comes bundled with Node.js when you install it on your system.

Installation | Yarn

Then, commands would be like this.
Yarn packages are updated after installation.

sudo npm install --global yarn

Although mixed operation of different package mangers is generally unfavorable, not hesitate due to following reasons.

  • Scrap-and-build, and disposable are characteristic of WSL environment.
  • Packages other than Rails and its associated are not installed.
Gem installation

Update RubyGem, and check its conditions.
Outpus are provided at the end of this post.
Required Gem is only "rails"

sudo gem update --system
gem environment
gem list
sudo gem install rails

Operation check

To check access with a web browser, make new project. It is "testflight" here.
Associated project files are generated, run server at the project folder.

rails new testflight
cd testflight
rails server

Access "localhost:3000" from Windows side. The images attached at top of this post is its output.
No erros are reported in the console at this connection.
Looks everything seems fine.
f:id:espio999:20210428115925p:plain

Then, export this image and reuse it according to the needs.

wsl --export Ubuntu ubuntu_rails.tar

impsbl.hatenablog.jp
The post above introduces how to import Docker container to WSL. My initial idea was importing the official Rails container in a similar way. But it doesn't recommended because this image has not been updated since the end of 2016.
According to the description there, the value of this package is the pre-installing of Node.js and databases.

For most usages of this image, it was already not bringing in rails from this image, but actually from your project's Gemfile, so the only "value" being added here was the pre-installing of nodejs, mysql-client, postgresql-client, and sqlite3 for various uses of the rails framework.

Docker Hub

Gem

gem environment

Outputs

wsluser@paulownia:~$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 3.1.2
  - RUBY VERSION: 2.7.0 (2019-12-25 patchlevel 0) [x86_64-linux-gnu]
  - INSTALLATION DIRECTORY: /var/lib/gems/2.7.0
  - USER INSTALLATION DIRECTORY: /home/wsluser/.gem/ruby/2.7.0
  - RUBY EXECUTABLE: /usr/bin/ruby2.7
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - SPEC CACHE DIRECTORY: /home/wsluser/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /var/lib/gems/2.7.0
     - /home/wsluser/.gem/ruby/2.7.0
     - /usr/lib/ruby/gems/2.7.0
     - /usr/share/rubygems-integration/2.7.0
     - /usr/share/rubygems-integration/all
     - /usr/lib/x86_64-linux-gnu/rubygems-integration/2.7.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games
     - /usr/local/games
     - /mnt/c/Users/.../DOCUME~1/MobaXterm/slash/bin
     - /mnt/c/WINDOWS/
     - /mnt/c/WINDOWS/system32/
     - /snap/bin
wsluser@paulownia:~$


gem list

Outputs

wsluser@paulownia:~$ gem list

*** LOCAL GEMS ***

benchmark (default: 0.1.0)
bigdecimal (default: 2.0.0)
bundler (default: 2.1.2)
cgi (default: 0.1.0)
csv (default: 3.1.2)
date (default: 3.0.0)
dbm (default: 1.1.0)
delegate (default: 0.1.0)
did_you_mean (default: 1.4.0)
etc (default: 1.1.0)
fcntl (default: 1.0.0)
fiddle (default: 1.0.0)
fileutils (default: 1.4.1)
forwardable (default: 1.3.1)
gdbm (default: 2.1.0)
getoptlong (default: 0.1.0)
io-console (default: 0.5.3)
ipaddr (default: 1.2.2)
irb (default: 1.2.1)
json (default: 2.3.0)
logger (default: 1.4.2)
matrix (default: 0.2.0)
minitest (5.13.0)
mutex_m (default: 0.1.0)
net-pop (default: 0.1.0)
net-smtp (default: 0.1.0)
net-telnet (0.1.1)
observer (default: 0.1.0)
open3 (default: 0.1.0)
openssl (default: 2.1.2)
ostruct (default: 0.2.0)
power_assert (1.1.7)
prime (default: 0.1.1)
pstore (default: 0.1.0)
psych (default: 3.1.0)
racc (default: 1.4.16)
rake (13.0.1)
rdoc (default: 6.2.1)
readline (default: 0.0.2)
readline-ext (default: 0.1.0)
reline (default: 0.1.2)
rexml (default: 3.2.3)
rss (default: 0.2.8)
rubygems-update (3.2.16)
sdbm (default: 1.0.0)
singleton (default: 0.1.0)
stringio (default: 0.1.0)
strscan (default: 1.0.3)
test-unit (3.3.5)
timeout (default: 0.1.0)
tracer (default: 0.1.0)
uri (default: 0.10.0)
webrick (default: 1.6.0)
xmlrpc (0.3.0)
yaml (default: 0.1.0)
zlib (default: 1.1.0)
wsluser@paulownia:~$