owned this note
owned this note
Published
Linked with GitHub
---
title: WSL Install
tags: Note_Linux, Docker, Linux
description: Docker, Linux, Program, Online
---
# [WSL Install](https://hackmd.io/@billsun/BJByCIUHf)
> Windows Subsystem for Linux (WSL)
## 事前須知 作業系統
* Windows 10 家用版,版本 1903 或更高版本,含 組建 18362 或更高組建。 (x64 的處理器)
* Windows 10,版本 2004 或更高版本,含 組建 19041 或更高組建。 (ARM64 的處理器)

## 方法
> 到「控制台 > 程式與功能」,點擊「開啟或關閉 Windows 功能」。

> 要重開機才能繼續安裝,學校教室有防寫, 如果沒有一開始沒有開這二個選項, 就不用試。
## [使用 WSL 在 Windows 上安裝 Linux](https://learn.microsoft.com/zh-tw/windows/wsl/install)
[WSL 的基本命令](https://learn.microsoft.com/zh-tw/windows/wsl/basic-commands?source=recommendations)
PowerShell上執行
執行 wsl --list --online 以查看可用的版本清單
> wsl -l -o
```shell=
wsl -l -o
wsl --update
wsl -l -o
```
wsl --install -d <DistroName> 以安裝散發版本。
> wsl --install -d Ubuntu
> wsl --install -d Ubuntu-20.04
```shell=
wsl --install -d Ubuntu-20.04
```
下載和安裝, 第一次啟動, 新增使用者 user

In Windows 10 PowerShell 列出已安裝的 Linux 發行版本,此命令也可以輸入為:wsl -l -v
```shell=
wsl --list --verbose
```
WSL 忘記密碼
```shell=
wsl -d Ubuntu-22.04 --user root
```
[Install GCC on Ubuntu 22.04](https://www.cherryservers.com/blog/how-to-install-gcc-on-ubuntu)
Windows 終端機可以從 [Windows 商店](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701?hl=zh-tw&gl=tw) 取得
在終端機可選擇進入那個作業系列

>目前Ubuntu STATE 為Stopped會發生上課遇到的錯誤,
>[處理結束,代碼為 4294967295 (0xffffffff)]
>可用 wsl --install -d Ubuntu ,即可進入Ubuntu,
>再用 wsl --list --verbose, Ubuntu STATE 為 Running
或用下列方法
```
C:\Windows\system32\wsl.exe -d Ubuntu-20.04
改成
"C:\Windows\system32\wsl.exe" ~ -d Ubuntu-20.04
```

## [How to Fix WSL: Error code: WSL/Service/0x80040326](https://localusr.com/posts/2023/03/01-fix-wsl-0x80040326-error/)
> When you use Windows 10/11 with the WSL service, you can encounter the following error
```
Error: 0x80040326
Error code: Wsl/Service/0x80040326
```
1. Open Windows Powershell in administrator mode
2. Update WSL and shut it down completely
```shell=
PS C:\Users\mossad> wsl --update
Checking for updates.
Updating Windows Subsystem for Linux...
PS C:\Users\martinmusale> wsl --shutdown
```
3. Test that the error is fixed
```shell=
PS C:\Users\martinmusale> wsl -d Ubuntu-20.04
```
```shell=
sudo apt install python3
sudo apt install python-is-python3
python --version
sudo apt update
sudo apt upgrade -y
sudo apt install python3-pip
```

> 2023/02/21回家作業
```shell=
df
cd /mnt/d
ls -l
curl ifconfig.me
python --version
```
>
* df:df 是一個查看硬碟空間使用情況的指令。它會列出硬碟分區的大小、已用空間和可用空間等資訊。
* cd /mnt/d:cd 是目錄切換的。在這裡,這個指令將當前工作目錄更改為 /mnt/d。
* ls -l:ls 是列出目錄內容,而 -l 則是將內容以長格式(即列出每個檔案或目錄的詳細資訊,例如擁有者、權限、檔案大小等)列出。
* curl ifconfig.me:curl 是一個用於從命令列中下載或上傳資料的指令。ifconfig.me 是一個用於獲取您的公用 IP 地址的網站。這個命令將使用 curl 訪問該網站,並將使用者的對外連線 IP 地址輸出到命令列中。
* python --version:python 是一程式語言,而 --version 用於顯示系統中安裝的 Python 版本。
## [How to install Nginx + php + MySQL on WSL Ubuntu 20.04- Windows 10] (https://www.how2shout.com/how-to/install-nginx-php-mysql-on-wsl-ubuntu-20-04-windows-10.html)
需要一些時間
```shell=
sudo apt update
```
sudo apt upgrade先不做,太花時間了
> sudo apt upgrade
```shell=
sudo apt-get install php7.4-cli php7.4-fpm php7.4-curl php7.4-gd php7.4-mysql php7.4-mbstring zip unzip
```
```shell=
sudo apt install nginx
```
Start Nginx services
```shell=
sudo service nginx start
```
Access Nginx through the browser
> http://127.0.0.1 or http://localhost or http://your-system-ipaddress
## [HxD is a hex editor](https://mh-nexus.de/en/downloads.php?product=HxD20)
四則運算
### Input
輸入一個字串,其中包含運算元及運算子,為了方便讀取,所有的運算子及運算元均以空格區隔。
運算元為 0 ~$2^{31}-1$ 的整數
運算子則包含 + - * / % 及 ( )
運算時請注意先乘除後加減及() 優先運算的計算規則
```=
3+2*2
(1+(4+5+2)-3)+(6+8)
3+5 / 2
```
### Output
輸出結果。為了避免小數點誤差,所有的運算過程都不會產生小數點,可以放心使用整數進行運算
```=
7
23
5
```
#### Answer
```python=
import sys
for s in sys.stdin:
print(eval(s.replace("/", "//")))
```
# 以1970-01-01開始的總天數, Python 在Windows 的雷
:::info
以1970-01-01開始的總天數為0,對應到的日期為 '1970-01-01'
以1970-01-01開始的總天數為1,對應到的日期為 '1970-01-02'
以1970-01-01開始的總天數為18039,對應到的日期為 '2019-05-23'
以1970-01-01開始的總天數為18405,對應到的日期為 '2020-05-23'
:::
:::danger
在Linux和Mac正常,在Windows無法跑,會出現OverflowError錯誤訊息
```shell
Traceback (most recent call last):
File "time.py", line 6, in <module>
end_sec2 = time.mktime(time.strptime(end_date,'%Y-%m-%d')) + date_time * (24*60*60)
OverflowError: mktime argument out of range
```
:::
#### Answer
```python=
import time
import datetime
date_time = 0
end_date = '1970-01-01'
end_sec2 = time.mktime(time.strptime(end_date,'%Y-%m-%d')) + date_time * (24*60*60)
print(time.strftime("%Y-%m-%d", time.localtime(end_sec2)) )
```
---

ZeroJudge d074
```
5
42 39 41 43 30
```
```python=
input()
print(max(list(map(int,input().split()))))
```
```python=
t=input();print(max([int(x) for x in input().split()]))
```
基礎使用
---
- [repl.it] repl.it
WSL Ubuntu 20.04 Node v18.17.1 Install
==
```shell=
sudo apt install python3
sudo apt install python-is-python3
python --version
```
安裝 Node v18.17.1
```shell=
sudo apt-get install -y curl
sudo curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
```
出現的提示:
```
## Run `sudo apt-get install -y nodejs` to install Node.js 18.x and npm
## You may also need development tools to build native addons:
sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
```
依提示安裝下列程式:
```shell=
sudo apt-get install -y nodejs
sudo apt-get install -y gcc g++ make
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install -y yarn
```
很重要的檢查方式, 要 node --version 和 sudo node --version 都能看到 v18.17.1 的版本
```shell=
user@402-PC09:~$ node --version
v18.17.1
user@402-PC09:~$ sudo node --version
v18.17.1
```
確認之後, 才能安裝 DOLOS
```shell=
user@402-PC09:~$ sudo npm install -g npm@10.1.0
user@402-PC09:~$ sudo npm install -g @dodona/dolos
```
```
added 232 packages in 31s
31 packages are looking for funding
run `npm fund` for details
```
很重要的檢查方式, 要能看到以下三列的顯示結果
```shell=
$ dolos --version
```
能看到以下三列
```
Dolos v2.3.0
Node v18.17.1
Tree-sitter v0.20.5
```
WSL Ubuntu 20.04可共用 Windows 的資料匣, 但要用 cd /mnt/e/ 來切資料匣
```shell=
#cd /mnt/e/Python/
cd /mnt/d/linux/
wget http://ms.ntub.edu.tw/~shyong/ssl/Dolos.zip
sudo apt install unzip
unzip Dolos.zip
cd Dolos/student_P
dolos run -f web -l python *.py
```
是否需要 --host 0.0.0.0 , 不同環境作法不一樣
http://localhost:3000/#/
```shell=
dolos run -f web -l python *.py
```
http://172.30.100.116:3000/#/
```shell=
dolos run -f web -l python *.py --host 0.0.0.0
```

```
find problem_A1 -type f -path "*/team*/correct*.py" -exec cp {} Dolos/problem_A1/ \;
```