해당 문서는 2023년 7월에 작성된 문서입니다.
윈도우에서 리눅스를 사용하기 위해 또는 Docker Desktop을 윈도우에 설치하기 위해서 가장 일반적으로 WSL을 사용하고 있습니다. 이 글에서는 WSL이 설치되었다는 가정하에 WSL의 기본 사용법에 대해 알아보겠습니다.

 

WSL 설치

https://learn.microsoft.com/ko-kr/windows/wsl/install
wsl 설치에 대해서는 위 링크를 참고하여 진행해 주시기 바랍니다.

 

WSL에 설치할 수 있는 배포 확인

먼저 wsl에서 지원하는 설치할 수 있는 배포에 대하여 알아봐야 합니다. 아래 명령어를 통하여 다음과 같이 지원하는 배포를 출력합니다.

> wsl -l -o

# 결과 #
다음은 설치할 수 있는 유효한 배포 목록입니다.
'wsl --install -d <배포>'를 사용하여 설치하세요.

NAME               FRIENDLY NAME
Ubuntu             Ubuntu
Debian             Debian GNU/Linux
kali-linux         Kali Linux Rolling
SLES-12            SUSE Linux Enterprise Server v12
SLES-15            SUSE Linux Enterprise Server v15
Ubuntu-18.04       Ubuntu 18.04 LTS
Ubuntu-20.04       Ubuntu 20.04 LTS
Ubuntu-22.04       Ubuntu 22.04 LTS
OracleLinux_8_5    Oracle Linux 8.5
OracleLinux_7_9    Oracle Linux 7.9

 

새로운 배포 설치

설치 가능한 배로를 확인하고 원하는 배포를 설치하면 됩니다. 저는 예시로 "Ubuntu-22.04"를 아래 명령어를 통하여 설치를 진행했습니다. 명령어를 수행하고 나면 user, password를 입력하여 설치를 완료합니다.

> wsl --install -d Ubuntu-22.04

# 결과 #
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: 
New password:
Retype new password:

 

배포 확인

맨 앞 "*" 표시가 있는 배포는 디폴트로 설정된 배포입니다.

> wsl -l -v

# 결과 #
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2
  Ubuntu-22.04           Running         2

 

배포 시작

만약 디폴트로 설정된 배포 실행하는 방법은 간단합니다. 그냥 아무런 옵션 없이 wsl만 입력하면 디폴트로 설정된 배포가 시작됩니다.

> wsl

# 원하는 경로에서 시작하기
> wsl 절대경로

이번에는 디폴트로 설정되지 않은 배포를 시작하는 방법에 대하여 알아보겠습니다. 예제로는 앞서 설치한 Ubuntu-22.04로 진행하였습니다.

> wsl -d Ubuntu-22.04

# 원하는 경로에서 시작하기
> wsl -d Ubuntu-22.04 절대경로

 

디폴트 배포 설정하기

자주 사용하는 배포를 디폴트로 설정하여 편리하게 사용할 수 있습니다.

# 디폴트 배포 변경하기
> wsl -s Ubuntu-22.04

# 확인
> wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-22.04           Running         2
  docker-desktop         Running         2
  Ubuntu                 Running         2
  docker-desktop-data    Running         2

 

배포 삭제하기

사용하지 않는 배포를 삭제하여 깔끔하게 정리합니다.

> wsl --unregister Ubuntu-22.04

지금까지 WSL에 대한 기본 사용법에 대해서 알아봤습니다. 보다 자세한 내용은 아래 링크 또는 "wsl --help"를 통하여 확인할 수 있습니다.
 https://learn.microsoft.com/ko-kr/windows/wsl/basic-commands?source=recommendations

 

기타 등등

# wsl 업데이트
wsl --update

# wsl 종료
wsl --shutdown

 

Go언어 처음 설치라면 2번부터 진행하시면 됩니다.

1. Go 제거하기

# go언어 제거 하기
sudo apt-get purge golang*
sudo rm -rf /usr/local/go
sudo rm -rf $(echo $GOPATH)

# ~/bashrc 또는 ~/.profile에서 go 관련된 항목 제거(기존에 설정한 파일에서 작업)
source ~/.profile
source ~/.bashrc

# 제거 확인
go version

 

2. apt-get 업데이트 하기

sudo apt-get update
sudo apt-get -y upgrade

 

3. wget 설치 확인 및 wget 설치

# wget 설치 확인 & wget 없을 경우 wget 설치
which wget
sudo apt-get install wget

 

4. Go 최신 버전 설치하기

https://go.dev/dl/

 

Downloads - The Go Programming Language

Downloads After downloading a binary release suitable for your system, please follow the installation instructions. If you are building from source, follow the source installation instructions. See the release history for more information about Go releases

go.dev

 

위 링크에서 최신 버전(현재 최신 버전은 1.19.2)의 linux-amd64.tar.gz에 우클릭하여 링크 주소를 복사하고 wget으로 다운로드합니다.

# go 다운로드
wget https://golang.org/dl/go1.19.2.linux-amd64.tar.gz

# 압축 풀기
sudo tar -C /usr/local -xvf go1.19.2.linux-amd64.tar.gz

# 환경변수 설정
mkdir ~/go
echo "export GOROOT=/usr/local/go" >> ~/.profile
echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.profile
echo "export GOPATH=$HOME/go" >> ~/.profile
source ~/.profile
echo $GOPATH

# go version 확인하기
go version

 

 

 

 

 

'Go언어' 카테고리의 다른 글

golang version upgrade (ubuntu)  (0) 2023.07.09
go work 사용해보기  (0) 2023.07.06
Go언어 interface reflect  (0) 2021.08.15
Go언어 Cron  (0) 2021.06.15
Prometheus Go언어 Metric label  (0) 2021.06.14

+ Recent posts