[LINUX] I tried to build an environment with WSL + Ubuntu + VS Code in a Windows environment

Introduction

Start learning programming with Windows! I thought that I should be able to easily build an environment for those who like: relieved: This time, I wanted everyone in the study group to hit the command with node.js and display the output result, so I ran to introduce Linux (Ubuntu).

What is WSL? What is Ubuntu?

WSL WSL is a subsystem that realizes the execution environment of Linux on Windows OS. In short, you can use Linux as an application! !! !! !! Linux and Windows on one computer? !! It's like WSL (laughs) Ubuntu What is Ubuntu? Linux [Distribution](https://ja.wikipedia.org/wiki/Linux%E3%83%87%E3%82%A3%E3%82%B9%E3%83%88%E3%83 % AA% E3% 83% 93% E3% 83% A5% E3% 83% BC% E3% 82% B7% E3% 83% A7% E3% 83% B3) One OS (operating system). Ubuntu is easy to use anyway! I don't really understand that, (Is it lacking in study or understanding?) Detailed explanation is Wikipedia

Environment

Procedure ① Enable Windows Subsystem for Linux (WSL)

Before installing the Linux distribution (Ubuntu) on Windows, you must first enable the "Windows Subsystem for Linux". -Open PowerShell as an'administrator'and execute the following command → Right-click the Windows icon at the bottom left and click "Windows PowerShell (Administrator)".

  Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

・ Restart your computer

Step ② Install Ubuntu

-Start "Microsoft Store" and search for "Ubuntu" ・ Open "Ubuntu 20.04 LTS" ・ Click Get to start downloading automatically ・ When you receive the download completion notification, click "Start". After starting, the following contents will be displayed, enter the user name and password to complete the installation !!!

  Installing, this may take a few minutes...
  Please create a default UNIX user account. The username does not need to 
  match your Windows username.
  For more information visit: https://aka.ms/wslusers
  Enter new UNIX username: user
  Enter new UNIX password:
  Retype new UNIX password:
  passwd: password updated successfully
  Installation successful!
  To run a command as administrator (user "root"), use "sudo <command>".
  See "man sudo_root" for details.

  user@:~$

Step ③ Update Ubuntu

Update ubuntu with the following command. You will be asked for a password, so enter the password you entered above.

sudo apt update
sudo apt upgrade

Step ④ Install Node.js in WSL (Ubuntu 20.04 LTS) environment

・ Add repository

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

・ Install nodejs with apt

sudo apt install -y nodejs

・ Select Yes when a confirmation message arrives -Check if nodejs and npm are installed

node --version
npm --version

Step ⑤ Install VS Code

Then Install if VScode is not already installed. Note that VScode is always installed on the Windows side, not the WSL side.

Step ⑤ Add an extension to VS Code

Next, add the VScode extension (Remote --WSL) for Remote Development. Click the "Install" button to start VScode. Follow the message to install. index.js - practice [WSL_ Ubuntu-20.04] - Visual Studio Code  2020_11_17 12_52_25 (1).png Remote - WSL ↓ There is also an installation method in the official document! Official Document

ようこそ - Visual Studio Code 2020_11_17 12_58_06.png Click the green part at the bottom left as shown in the image above ようこそ - Visual Studio Code 2020_11_17 12_58_18.png Then, it will appear as shown in the image above, so click Remote WSL New Window You can now use WSL with VS Code! (WSL: Ubuntu-20.04 is written for WSL like the green part at the bottom left of the first image)

Let's output the command with Node.js

-Since there is "File / Edit / Select / View / Move / Run / Terminal / Help" at the top of VS Code, click Terminal and click "New Terminal". ・ The terminal appears at the bottom of the screen! Below: Run in the terminal

Let's hit the command with Unix command! !!

→ Create a practice directory

mkdir practice

→ Move to practice directory

cd practice

→ Create a js file called main in the practice directory

touch main.js

Now you are ready!

Let's display the input result

Select the "lesson" created earlier from the Open folder Since there is a main.js file, in it

console.log('Hello Tech.Uni')

Type and save! !! !! (Be careful because it's easy to forget (laughs)) This time to the terminal

node main.js

Type Enter !!!! It looks like the image below is perfect: blush: main.js - lesson [WSL_ Ubuntu-20.04] - Visual Studio Code  2020_11_17 13_33_10.png

Thank you for your hard work!

References

Installation Guide for Windows Subsystem for Linux for Windows 10

https://docs.microsoft.com/ja-jp/windows/wsl/install-win10

Visual Studio Code's "Remote – WSL" is insanely useful

https://syobon.jp/blog/2019/11/04/visual-studio-code-remote-wsl/

Recommended Posts

I tried to build an environment with WSL + Ubuntu + VS Code in a Windows environment
I tried to build an environment of Ubuntu 20.04 LTS + ROS2 with Raspberry Pi 4
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
When I tried to build a Rails environment on WSL2 (Ubuntu 20.04LTS), I stumbled and fell.
Build a python execution environment with VS Code
I was addicted to creating a Python venv environment with VS Code
Steps to create a Python virtual environment with VS Code on Windows
I tried to build a Mac Python development environment with pythonz + direnv
Steps to build a Django environment with Win10 WSL Ubuntu18.04 + Anaconda + Apache2
[Linux] WSL2 Build an environment for laravel7 with Ubuntu 20.04
[Go + Gin] I tried to build a Docker environment
How to debug a Python program by remotely connecting to a Docker container in WSL2 environment with VS Code
I tried to build an environment that can acquire, store, and analyze tweet data in WSL (bash)
I tried the super-resolution algorithm "PULSE" in a Windows environment
I tried to build an environment where work in the Docker container on the remote server can be done directly from the local VS Code with SSH connection
How to use VS Code in venv environment on windows
I tried to build an environment for machine learning with Python (Mac OS X)
I tried to create an article in Wiki.js with SQLAlchemy
Create a Python environment for professionals in VS Code on Windows
I tried to create a server environment that runs on Windows 10
Try to create a python environment with Visual Studio Code & WSL
How to build Python and Jupyter execution environment with VS Code
I want to build a Python environment
I made a tool to convert Jupyter py to ipynb with VS Code
I tried to create an environment where you can have a fun Zoom meeting with Linux (Ubuntu) + Zoom + OBS Studio + sound effects
I tried to build a super-resolution method / ESPCN
I tried to build a super-resolution method / SRCNN ①
I tried to integrate with Keras in TFv1.1
I tried Flask with Remote-Containers of VS Code
Python (Windows 10) Virtual Environment / Package with VS Code
Build a Django environment with Vagrant in 5 minutes
I tried to detect an object with M2Det!
Use Python in Anaconda environment with VS Code
I tried to build a super-resolution method / SRCNN ③
I tried to build a super-resolution method / SRCNN ②
Build a development environment using Jupyter and Flask with Python in Docker (supports both VS Code / code-server)
Build an environment to execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people)
When I tried to create a virtual environment with Python, it didn't work
I tried to extract a line art from an image with Deep Learning
I tried to create an environment to check regularly using Selenium with AWS Fargate
I tried to implement what seems to be a Windows snipping tool in Python
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
I tried to create a table only with Django
I want to transition with a button in flask
I tried to draw a route map with Python
I tried to implement a pseudo pachislot in Python
I made a Python3 environment on Ubuntu with direnv.
I tried to implement an artificial perceptron with python
I want to easily build a model-based development environment
I tried to build ML Pipeline with Cloud Composer
I want to work with a robot in python.
I tried to automatically generate a password with Python3
Introducing WSL (Ubuntu 18.04) to WIndows10 ~ Proxy environment second part ~
I tried to make an OCR application with PySimpleGUI
I tried to find an alternating series with tensorflow
Create an exe file that works in a Windows environment without Python with PyInstaller
A story about how Windows 10 users created an environment to use OpenCV3 with Python 3.5
I tried to create a reinforcement learning environment for Othello with Open AI gym
[Django] Use VS Code + Remote Containers to quickly build a Django container (Docker) development environment.
[AWS] Development environment version that tried to build a Python environment with eb [Elastic Beanstalk]
Memo A beginner tried to build a Java environment and Japaneseize it on Ubuntu 18.04.2 LTS.