[Windows] WSL2 + Ubuntu + Node.js environment construction

"I only have a Windows machine and I can't afford to buy a Mac ... but I want to do Web development in a proper environment", so I will write a memorandum on how to build a Linux-based development environment even in a Windows environment. ..

This time, the React book "Riakt! We will continue to build the environment by referring to the book.

Let's install WSL2 anyway

It's been a long time since I was told that "Web development on Windows is crazy", and Microsoft has taken serious steps to overcome such a situation and has significantly updated the system for touching Linux on Windows. Its name is ** WSL2 (Windows Subsystem for Linux 2) **!

Comparison of WSL 1 and WSL 2

In summary, ** memory-saving, fast, and complete Linux kernels now run on Windows **.

If you want to touch UNIX-like OS on Windows, you need to install this WSL2.

WSL works, but it seems that WSL2 will be used in the future unless there is a specific reason. When using WSL: Exceptionally when using WSL1 instead of WSL2

How to install WSL2

Installation of WSL2 was okay if you followed the flow of the official documentation below. In my case, the OS build was 19042.685 and I did a manual install. At the time of writing, it seems that OS build 20262 or later can be automatically installed with the command wsl --install. It helps.

Installation Guide for Windows Subsystem for Linux for Windows 10

What are the precautions for installation?

--Powershell runs with administrator privileges --Check if the Windows build meets the WSL2 requirements ――It may be useful later if you also include "Windows Terminal" after the installation is complete.

Adjust WSL settings

After installing Linux, make the initial settings. Creating a file called wsl.conf and making the necessary settings first will make the rest easier.

sudo vi /etc/wsl.conf

Create wsl.conf as, and write the contents of the file as appropriate. This time, I will write only the part related to access authority for the time being.

wsl.conf


[automount]
options = "metadata,umask=22,fmask=11"

Reference: https://docs.microsoft.com/ja-jp/windows/wsl/wsl-config#configure-per-distro-launch-settings-with-wslconf https://www.atmarkit.co.jp/ait/articles/1807/12/news036.html

Package update

Update APT and installed packages.


sudo apt update
sudo apt -y upgrade

By the way, APT (Advanced Packaging Tool) is a package management tool that is often used in Linux. Reference: https://ja.wikipedia.org/wiki/APT

Install Git

Git, an essential tool for engineers, is also included here.

sudo apt-get install -y git

When the shell is ZSH

It seems that ZSH (Z Bash), which is a stronger version of Bash, is popular, so I'll put it in (I'm going to meet someone stronger than me). I didn't know ZSH or fish because I was too ignorant of the Linux area.

sudo apt-get -y zsh
chsh -s /usr/bin/zsh

Install Node.js

Install anyenv before installing node.js. anyenv is a tool that can manage multiple ** env systems at once. It seems that you can use it to manage multiple versions of multiple languages. Convenient!

In other words, it feels like installing in the order of anyenv → nodenv → required plugins → Node.js.

Clogged with installing anyenv

When I was thinking "It's node.js through the path", the following message came out.

ANYENV_DEFINITION_ROOT(/home/user_name/.config/anyenv/anyenv-install) doesn't exist. You can initialize it by:
> anyenv install --init

Even if I did this, it didn't run well and I was in trouble. That is the order of description in .zshrc.

.zshrc


PATH="$HOME/.anyenv/bin:$PATH"
eval "$(anyenv init -)"

I wrote upside down what I should do as above. Then I ran anyenv install --init as in the message and it worked.

The following article was helpful for the introduction of anyenv.

anyenv + macOS environment construction

(Because I grew up in a Windows field, I have a lot of trouble with Linux that I just touched in college classes ...)

installation of nodenv

nodenv is a version control tool for Node.js. If you can solve the above problem, you can install nodenv in one shot.

anyenv install nodenv

Don't forget to restart the shell with exec $ SHELL -l after installation.

Installation of required plugins

At this timing, install useful plugins. This time, enter anyenv-update and nodenv-default-packages. Create a plugins directory directly under the root directory and put it there.

anyenv-update is an anyenv plugin that updates all" ** env ". nodenv-default-packages is a nodenv plugin that allows you to specify which packages to install with npm.

Then, create a configuration file for nodenv-default-packages directly under nodenv. This time, I set it as follows.

default-packages


yarn
typescript
ts-node
typesync

Install Node.js

The installation of Node.js is as follows. Following the book, the version is 14.4.0.

nodenv install -l
nodenv install 14.4.0
nodenv global 14.4.0

Here's what we're doing:

  1. Look at the version list
  2. Install the version you are looking for
  3. Set the default version

Summary

I managed to set up the environment because I developed Windows like Macs. I feel like I've finally stood one step before the starting line. When I tried this time, I realized that my knowledge of UNIX-like commands was overwhelmingly insufficient.

I will do my best while having fun.

Recommended Posts

[Windows] WSL2 + Ubuntu + Node.js environment construction
Penronse environment construction [Windows]
[Flutter] Ubuntu 20.04 environment construction
Try running ScalarDB on WSL Ubuntu (Environment Construction)
Laravel environment construction (Ubuntu 18.04 LTS)
I built an Ubuntu environment on Windows 10 using WSL2.
Windows10 + WSL2 + DockerDesktop + docker-compose + GPU (Nvidia) + Jupyterlab environment construction
Node.js environment construction with Docker Compose
Troublesome Rails environment construction flow [Windows 10]
WSL2 + Ubuntu 20.04 Install Vivado in LTS environment
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
[Java] Environment construction
Java environment construction
[Spring] Environment construction
Docker environment construction
Protobuf and gRPC C ++ environment construction on Ubuntu 18.04
[Ubuntu 18.04] Environment construction for using PyTorch with RTX3090
Create ubuntu20.04 (or windows10) + anaconda + pytorch or tensorflow environment
[Personal memo] Ruby on Rails environment construction (Windows)
[Environment construction] Eclipse installation
Rails Docker environment construction
Server construction procedure Ubuntu18.04 server
[Mac] VS Code development environment construction (Java, Gradle, Node.js)
Circle CI environment construction
Create an environment where CircleCI can be executed locally with Windows10 + WSL2 (Ubuntu) + Docker
java development environment construction
Install Rust in WSL2 Ubuntu environment and build WASM build environment
ubuntu on wsl part 10
Cross-compile Qt – GUI Windows Application in Ubuntu 18.04 MinGW environment
Beginners use ubuntu in windows to prepare rails environment
Java + Spring development environment construction with VirtualBox + Ubuntu (Xfce4)
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker
Deploying a Java environment with Windows Subsystem for Linux (WSL)
[CCNA] Construction of Cisco device emulator environment (EC2 + Ubuntu + GNS3)
Case that gave up environment construction of react with ubuntu
Windows10 Eclipse environment construction & what are you doing Fukahori August 2020
Rails6 development environment construction [Mac]
[Spring Boot] Environment construction (macOS)
WSL2 + VSCode + Docker development environment
Rails engineer environment construction ruby2.7.1
EC-CUBE4 environment construction (local edition)
I tried node-jt400 (Environment construction)
Rails6 (MySQL, Ubuntu environment, Cloud9)
Ubuntu on Windows Community Preview
Rails environment construction Rails5.2.1 ruby2.5.1 Catalina
MySQL 5.7 (Docker) environment construction memo
Introduction to Metabase ~ Environment Construction ~
Install Java on WSL Ubuntu 18.04
Ruby installation on WSL2 + Ubuntu 20.04
JavaFX environment construction in Java 13
Redmine (Docker) environment construction memo
Ubuntu on Windows build speed
[Docker] Rails 5.2 environment construction with docker
AtCoder Challenge Environment Construction (Java 8)
Build docker environment with WSL
Offline environment construction Ruby edition
Docker × Spring Boot environment construction
[Super easy] Ruby environment construction
[Rails / MySQL] Mac environment construction
Ruby ① Build a Windows environment
[Docker] postgres, pgadmin4 environment construction