Skip to main content

Command Palette

Search for a command to run...

WSL2 Ruby on Rails 开发环境搭建笔记

Updated
1 min read
WSL2 Ruby on Rails 开发环境搭建笔记

没有 systemd 的补救方式

pg、redis、docker 等服务的自启动 /etc/init.wsl

# /etc/init.wsl
#! /bin/sh
sysctl -w vm.max_map_count=262144
pg_ctlcluster 13 main start
service redis-server start
service docker start

win 端开机自启动 vbs 脚本

# C:\Users\[Your User Name]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\wsl-start.vbs
Set ws = WScript.CreateObject("WScript.Shell")        
ws.run "wsl -d ubuntu -u root /etc/init.wsl"

WSL2 开始支持 systemd 了,找个时间切过去

网络代理设置

虽然家里有软路由,但是考虑到带笔记本出门的场景,选择在笔记本上运行 clash for windows,WSL2 Ubuntu 通过设置 HTTP_PROXY 等环境变量来使用 windows 端提供的代理。

最终方案,Ubuntu 中通过 proxy_on/proxy_off 来开关代理

function proxy_on() {
  export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*')
  export https_proxy="http://${hostip}:7890"
  export http_proxy="http://${hostip}:7890"
  export no_proxy="localhost,127.0.0.1,::1,.local"
  export HTTP_PROXY=$http_proxy
  export HTTPS_PROXY=$http_proxy
  export NO_PROXY=$no_proxy
  git config --global http.proxy "socks5://${hostip}:7890"
  git config --global https.proxy "socks5://${hostip}:7890"
  echo -e "Proxy enabled"
}
# enable proxy by default
proxy_on

function proxy_off(){
    unset hostip http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY
    git config --global --unset http.proxy
    git config --global --unset https.proxy
    echo -e "Proxy disabled"
}

指定 Github 的 SSH 连接使用 443 端口(因为机场不支持代理 22 端口)

# ~/.ssh/config
Host github.com
  HostName ssh.github.com
  Port 443
  User git

RubyMine Git 修复

WSL2 git & jetbrains https://youtrack.jetbrains.com/issue/IDEA-276250

RubyMine 调教 for Rails Engines pattern

https://youtrack.jetbrains.com/issue/RUBY-18315/Allow-vendorengines-and-vendorgems-to-be-considered-project-not-library-code#focus=Comments-27-1608735.0-0