"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.
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) **!
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
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.
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
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
Git, an essential tool for engineers, is also included here.
sudo apt-get install -y git
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 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.
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.
(Because I grew up in a Windows field, I have a lot of trouble with Linux that I just touched in college classes ...)
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.
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
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:
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.