LoginSignup
40
47

More than 3 years have passed since last update.

【WSL(Windows Subsystem for Linux)】Proxy環境でのインストール

Last updated at Posted at 2019-09-25

Proxy環境でWSLの利用をあきらめていましたが、コマンドラインを使用してインストールができたので、忘備録としてまとめます。

追記:インストール用のバッチファイルを作成したので、本稿の最後にまとめて掲載しております。

環境

  • Windows 10 Pro
  • Proxy環境でMicrosoft Storeが使えない

MS Storeを使用せずにインストール

以下の記事を参考にコマンドラインからインストールしました。

WSL (Windows Subsystem for Linux) をコマンドラインでインストールする

Proxy の設定方法

デフォルトのエディタをVimに設定

sudo update-alternatives --set editor $(update-alternatives --list editor | grep 'vim.basic')

.bashrcを編集

vim ~/.bashrc

.bashrc に環境変数を追記します。※id, pass, proxysrv, portは適宜修正

.~/.bashrc
export HTTP_PROXY_USER=id
export HTTP_PROXY_PASS=pass
export HTTP_PROXY=http://${HTTP_PROXY_USER}:${HTTP_PROXY_PASS}@proxysrv:port/
export HTTPS_PROXY=${HTTP_PROXY}

aptのプロキシ設定

/etc/apt/apt.conf を新規作成して、以下の内容を記載します。※id, pass, proxysrv, portは適宜修正

/etc/apt/apt.conf
Acquire::http::proxy "http://id:pass@proxysrv:port/";
Acquire::https::proxy "https://id:pass@proxysrv:port/";

そのほかプロキシ設定について

git, wget, pipなどのプロキシ設定は、以下の参考サイトがおすすめです。本稿では割愛いたします。

パッケージを更新

# リポジトリ一覧を更新
sudo apt update -y
# パッケージを更新
sudo apt upgrade -y

まとめ

Ubuntuインストール用バッチ

ProxyPassword, ProxyUsername, ProxyServerNameは適宜修正

install_Ubuntu.ps1
# You need to Execute this command and reboot in advance.
# Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

# Password Setting
$secPasswd=ConvertTo-SecureString <ProxyPassword> -AsPlainText -Force
# User and Credential Setting
$myCreds=New-Object System.Management.Automation.PSCredential -ArgumentList <ProxyUsername>,$secPasswd

# Download Image
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile $home/Ubuntu.appx -Proxy <ProxyServerName> -proxyCredential $myCreds

# Unzip File
Rename-Item $home\Ubuntu.appx $home\Ubuntu.zip
Expand-Archive $home\Ubuntu.zip $home\Ubuntu

# Create Shortcut in Desktop
cd $home\Ubuntu
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\ubuntu1804.lnk")
$Shortcut.TargetPath = "$home\Ubuntu\ubuntu1804.exe"
$Shortcut.Save()

Proxy setting用バッチ

id, pass, proxysrv, portは適宜修正
<suPassword> には、su(スーパーユーザー)のパスワードを指定

setting_ubuntu.sh
#!/bin/bash

# setting http proxy
cat <<'EOF' >> ~/.bashrc

# http proxy setting
export HTTP_PROXY_USER=id
export HTTP_PROXY_PASS=pass
export HTTP_PROXY=http://${HTTP_PROXY_USER}:${HTTP_PROXY_PASS}@proxysrv:port/
export HTTPS_PROXY=${HTTP_PROXY}

# git proxy setting
git config --global http.proxy ${HTTP_PROXY}
git config --global https.proxy ${HTTPS_PROXY}
git config --global url."https://".insteadOf git://
EOF

# setting apt proxy
echo <suPassword> | sudo tee /etc/apt/apt.conf <<EOF > /dev/null
Acquire::http::proxy "http://id:pass@proxysrv:port/";
Acquire::https::proxy "https://id:pass@proxysrv:port/";
EOF


# setting wget proxy
echo <suPassword> | sudo tee -a /etc/wgetrc <<EOF > /dev/null

# wget proxy setting
https_proxy = http://id:pass@proxysrv:port/
http_proxy = http://id:pass@proxysrv:port/
ftp_proxy = http://id:pass@proxysrv:port/
EOF

参考

Proxy内環境でWindows10にWSL開発構築する手順 #LinuxでProxy認証を突破する。

以上

40
47
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
40
47