ノンカフェインであなたにやさしい

Ruby,Rails,HTML,CSS,Reactなど

個人的Windowsを買ったときのセットアップ

毎回するセットアップのメモ

とりあえずインストール

WSL Ubuntuセットアップ

# とりあえずパッケージアプデ
sudo apt update
sudo apt upgrade

# ライブラリ系
sudo apt-get install -y libnss3-dev libatk1.0-0 libatk-bridge2.0-0 libcups2-dev libxkbcommon.so.0 libgbm-dev libgtk-3-0 libmysqlclient-dev imagemagick libmagickwand-dev mysql-client
sudo ln -s /usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16/Magick-config /usr/bin/Magick-config
export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig

# https://qiita.com/mtsgi/items/8a844870f30b30ef21e4#fluent-terminal
sudo apt install build-essential curl file

# Linux brew
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

# git
brew intall git
git config --global user.name 'akinov'
git config --global user.email  'メアド'

# zsh
brew install zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions

# peco
brew install peco

# rbenv
brew install rbenv
sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev
rbenv install 2.6.6
rbenv global 2.6.6
rbenv rehash

# nodenv
brew install anyenv
echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(anyenv init -)"' >> ~/.zshrc
eval "$(anyenv init -)"
anyenv install --init
anyenv install nodenv
exec $SHELL -l
nodenv install 15.12.0
nodenv global 15.12.0

# pg
sudo apt install postgresql
sudo apt install libpq-dev

brew install imagemagick

chromedriverインストール

akinov.hatenablog.com

.zshrc 関係

# alias
alias g='git'
alias rs='rails s'
alias rs4='rails s -p 4000'
alias rc='rails c'
alias cre='rails db:create'
alias mig='rails db:migrate'
alias rol='rails db:rollback'
alias seed='rails db:seed'
alias drop='rails db:drop'
alias rr='rake routes'
alias be='bundle exec'
alias bi='bundle install'
alias pbcopy='clip.exe'
alias dc='docker-compose'

# peco
function peco-history-selection() {
    BUFFER=`history -n 1 | tac  | awk '!a[$0]++' | peco`
    CURSOR=$#BUFFER
    zle reset-prompt
}

zle -N peco-history-selection
bindkey '^R' peco-history-selection

# rbenv
eval "$(rbenv init -)"

# nodenv
eval "$(nodenv init -)"

.gitconfig

[core]
        autocrlf = false
        ignorecase = false
        editor = vi
[color]
        ui = true
[pull]
        ff = only
[alias]
        co = checkout
        br = branch
        cm = commit
        st = status
        last = log -1 HEAD
        sw = switch
        swc = switch -c
        delete-merged-branch = !git branch --merged | egrep -v '\\*|master|release' | xargs git branch -d
[fetch]
        prune = true
[push]
        default = simple

エイリアス参照 【.zshrc解説】コピペで簡単zshカスタマイズ【設定方法】

環境構築で参照 WSL2でWeb開発環境の構築メモ (zsh, node, dockerなど)

anyenv系で参照 WSL2 + VScode + nodenv(anyenv)の環境構築方法まとめ - Qiita

rmagikインストールで参照

RMagickの環境構築 - Qiita

Your bundle is locked to mimemagic (0.3.5), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of mimemagic (0.3.5) has removed it. You'll need to update your bundle to a

Railsプロジェクトを動かそうとしたら下記のエラー

Your bundle is locked to mimemagic (0.3.5), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of mimemagic (0.3.5) has removed it. You'll need to update your bundle to a version other than mimemagic (0.3.5) that hasn't been removed in order to install.

mimemagic の指定しているバージョンが yanked になってしまったよう

rubygems.org

対応

bundle update してバージョンアップ

bundle update minemagic

WSL2に立てたサーバーに同ネットワークにある別端末からアクセスする

WSL上で開発をしていて立てたサーバーに別端末からアクセスする方法です。
Macでは何もせずにアクセスできたのですが、WSLの場合、Windows側にポートフォワーディングを設定する必要があります。

WSLのIPを調べる

ifconfig で確認
172.21.171.162 の部分

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.21.171.162  netmask 255.255.240.0  broadcast 172.21.175.255
        inet6 fe80::215:5dff:fe53:6719  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:53:67:19  txqueuelen 1000  (イーサネット)
        RX packets 25699  bytes 10913242 (10.9 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4954  bytes 2993879 (2.9 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (ローカルループバック)
        RX packets 109531  bytes 128195327 (128.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 109531  bytes 128195327 (128.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

PowerShellでポートフォワーディングを設定

※管理者として実行してください

netsh interface portproxy add v4tov4 listenport=3000 connectaddress=[先程調べたIP]

設定されているポートフォワーディングは

netsh interface portproxy show v4tov4 で確認可能

PS C:\WINDOWS\system32> netsh interface portproxy add v4tov4 listenport=3000 connectaddress=172.21.171.162

PS C:\WINDOWS\system32> netsh interface portproxy show v4tov4

ipv4 をリッスンする:         ipv4 に接続する:

Address         Port        Address         Port
--------------- ----------  --------------- ----------
*               3000        172.21.171.162  3000