Windows10+Ubuntu(WSL2) Ruby-on-Rails開發(fā)環(huán)境搭建
用了將近一年的Archlinux,不得不說Linux搞開發(fā)真的爽0Α!喷面!
However星瘾,問題太多了,只能滾回Windows惧辈。
環(huán)境要求
- CPU支持并且開啟虛擬化
- Windows 10 x64 版本 >= 18917
- 電腦配置好點(這玩意用的虛擬化琳状,說白了就是個虛擬機,占用較大的內(nèi)存)
第一步 - 打開WSL2
首先盒齿,請在系統(tǒng)設(shè)置里開啟開發(fā)者模式
# 以管理員身份打開Powershell
> dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# 重慶電腦念逞,配置新功能需要一點時間
> wsl --set-default-version 2
之后,安裝Ubuntu WSL
第二步 - 配套環(huán)境
默認的終端太丑了边翁,建議使用Fluent Terminal
如果要用oh-my-zsh翎承,可以先去下載Powerline字體
第三步 - 準備ruby
打開你的終端(開始菜單里的Ubuntu或者Fluent Terminal),跟著提示設(shè)置默認用戶和密碼
> sudo python oh-my-tuna.py --global # 用py修改apt鏡像源為清華tuna源
> sudo apt update # 刷新
> sudo apt upgrade # 升級現(xiàn)有的包
# rvm
> gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
> \curl -sSL https://get.rvm.io | bash -s stable
> echo "ruby_url=https://cache.ruby-china.com/pub/ruby" > /usr/local/rvm/user/db
> source ~/.bashrc
> source ~/.bash_profile
> rvm install ruby
> gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ # 修改gem鏡像源為ruby-china源
> bundle config mirror.https://rubygems.org https://gems.ruby-china.com
> gem install rails
第四步 - 準備nodejs&yarn
現(xiàn)在是前端的時代符匾,rails也內(nèi)置了webpacker叨咖,可以快速利用nodejs進行開發(fā)
Ubuntu源的nodejs和yarn都比較舊,我們需要安裝新版
# Nodejs
> curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
> sudo apt install nodejs
# yarn
> curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
> echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
> sudo apt update && sudo apt install yarn
# 淘寶鏡像
> npm config set registry https://registry.npm.taobao.org
> yarn config set registry https://registry.npm.taobao.org
# node-sass鏡像
> npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
> yarn config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
至此啊胶,基本的配置就結(jié)束了甸各!接下來就可以打開VSCode,利用remote擴展進行rails開發(fā)了焰坪。