- 投稿日:2020-01-16T16:35:01+09:00
swift version切り替える
Swiftバージョンを切り替える方法をメモします。
swiftenvのインストール
https://swiftenv.fuller.li/en/latest/installation.html
git cloneとHomebrewでのインストール方法を記載してくれています。
今回はHomebrewでインストール。まずは、インストール
brew install kylef/formulae/swiftenv`次に.bash_profileにパスの追加
echo 'if which swiftenv > /dev/null; then eval "$(swiftenv init -)"; fi' >> ~/.bash_profile`ローカルのSwiftバージョン確認
$ swiftenv versions * system 5.1.3ローカルのSwiftバージョンの変更
Swift バージョンのインストール
$ swiftenv install 5.0.1 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 305M 100 305M 0 0 2036k 0 0:02:33 0:02:33 --:--:-- 3658k Password: installer: Package name is Swift Open Source Xcode Toolchain installer: Installing at base path / installer: The install was successful. 5.0.1 has been installed.新しいSwiftバージョンをインストールしたら、こちらのコマンドの実行が必要のよう。
$ swiftenv rehashローカルのSwiftバージョン確認
swiftenv versions * 5.0.1 5.1.3無事に目的のSwift バージョンに切り替わってました
メモ:
Carthageが利用するSwiftバージョンが切り替わらない...誰か解る人いたら教えてください。
- 投稿日:2020-01-16T16:01:11+09:00
〇〇envのせいでzshの起動が遅いからチューニングした
概要
zshを起動するのに約4秒ほどかかっていた。あまりにもストレスだったので、どうにかして速くしてみた。
現環境では0.1秒まで速くなった。
結構前にやったことなので所々曖昧だが、残ってる記憶をメモしておく。
terminal環境は、
zsh + nvim + tmux
zshはプラグインを使用していない。
nvimではdein.vimを、tmuxでは表示系のプラグインを使用してる。測定と原因模索
測定
$ time (zsh -i -c exit)上記のコマンドでzshの起動時間を計測する。
初めて測ったときは、4秒くらいだった。原因を特定するために、以下を.zshenvの先頭に記述(.zshenvがない場合は.zshrc)
.zshenvzmodload zsh/zprof && zprofそして以下を.zshrcの最後に記述する
if (which zprof > /dev/null 2>&1) ;then zprof fi再測定すると以下のように表示される(下の表示は事後、また省略している)
$ time (zsh -i -c exit) num calls time self name ----------------------------------------------------------------------------------- num calls time self name ----------------------------------------------------------------------------------- 1) 2 43.39 21.70 66.15% 43.39 21.70 66.15% compaudit 2) 1 63.13 63.13 96.25% 19.74 19.74 30.09% compinit 3) 1 1.54 1.54 2.35% 1.54 1.54 2.35% colors ・ ・ ・結果、自分の場合は、〇〇envが原因だとわかった。
使用してるenvが、
- goenv
- pyenv
- rbenv
- direnv
- phpenv
がインストールされており、zsh起動時に読み込まれていた。
以下の初期化するコードが1秒ほどかかっていたので、〇〇envを遅延ロードする。eval "$(〇〇env init -)"その他はそこまで影響してなかった。
遅延ロード
まずは上記で原因がわかったので遅延ロードするシェルを書いた。
以下の処理は、コマンドが読み出されたときに初期化するコードが走り、コマンドが使用できるようになります。~/.zsh/lazyload.zshpyenv() { unfunction "$0" source <(pyenv init -) $0 "$@" } goenv() { unfunction "$0" source <(goenv init -) $0 "$@" } rbenv() { unfunction "$0" source <(rbenv init -) $0 "$@" } phpenv() { unfunction "$0" source <(phpenv init -) $0 "$@" } direnv() { unfunction "$0" source <(direnv hook zsh) $0 "$@" }.zshrcを分割してるので
~/.zsh/lazyload.zsh
というファイルに記述してる。
.zshrcの分割 : https://qiita.com/Suzuki09/items/80fbf9c6fcffa5c6b6b4direnvは使用する際に、
direnv allow
するのを忘れないこと。これを忘れていて別のプロジェクトで無駄に時間を使った。その他
.zshrcをコンパイルする。
% zcompile ~/.zshrczshの補完機能である、compinitが無駄に呼び出されていないか。
zshのプラグインマネージャーを剥がす。または別のプラグインマネージャーを使用する。zplugが有名だと思うが、速度ならばzpluginが速いらしい。
まとめ
一番の原因であった〇〇envを遅延ロードするだけでも、圧倒的に速くなったので良かった。
現環境の速度
% time (zsh -i -c exit) ( zsh -i -c exit; ) 0.05s user 0.03s system 85% cpu 0.089 total
- 投稿日:2020-01-16T15:28:46+09:00
Macで外付けUSBハードディスクをマウントする
問題
USBの外付けハードディスクがマウントされない状況が何度かあった。
使っている外付けハードディスクでは以下のように、2つのパーティションに分けていて、Macバックアップ のディスクはマウントされるが、もう片方がマウントされない現象。
- Macバックアップ
- Mac&Windows
マウント
/*ディスクの一覧表示*/ $ diskutil list /*一度外付けハードディスクをアンマウントする*/ $ diskutil unmountDisk /dev/disk2 /*マウントしたいディスクを指定しマウント*/ $ diskutil mount /dev/disk2s3これで指定したディスクをマウントすることができた。
- 投稿日:2020-01-16T12:33:53+09:00
Mac の terminalでTab 補完を有効にする2020年版
Macのterminal/iTerm2でTab補完をずっと前から有効にしたかったのですが、意外と古い情報ばかりでどれを信頼していいかわからなかったのでメモがわりに記載します。
結論
- bash-completionというパッケージをhomebrewでインストール
- .bash_profileを書き換える
- source .bash_profile で更新
- terminal 再起動
という感じでできるようになりました。参考した記事は
となります。
環境
macOS Mojave Version 10.14.6
Homebrew 2.2.3実際の手順
bash-completionというパッケージをhomebrewでインストール
homebrewがない場合は以下のサイト(これまた古いですが)からダウンロードしましょう。
ある場合は以下のコードをterminalで打ち込みます。
brew install bash-completion.bash_profileを書き換える
ない場合はホームディレクトリで
touch ~/.bash_profile
ある場合は
vi ~/.bash_profile ====================== #bash_profileに以下をコピペで記入する if [ -f $(brew --prefix)/etc/bash_completion ]; then . $(brew --prefix)/etc/bash_completion fiとして編集します。
source ~/.bash_profileで更新
最後にsourceで更新します。
source ~/.bash_profile
terminal再起動でできるはずです。
以上となります。
=============================
(蛇足ですが)他のウェブサイトの失敗した情報
他のウェブサイトだと(もう5年以上前のですが)、このような情報をホームディレクトリの
.inputrc
というファイルに書けばよいとも書かれていました。さっそく
.inputrc
ファイルを作りましてtouch .inputrc
vi ~/.inputrc
で開き、以下の内容を記入しましたが。。。set completion-ignore-case on TAB: menu-complete
結局Tab補完されなかったので、古い情報なのかな?とも思いました。
以下のサイトに書かれてある情報でした。
https://qiita.com/fantm21/items/7e9b23ddd8a958a93679
https://ameblo.jp/nekocat2/entry-11539657198.html最後に
もっと効率的な方法、確実な方法があるかもしれないので、コメント等でフィードバックいただけると嬉しいです。
- 投稿日:2020-01-16T10:23:35+09:00
MySQLを起動しようとすると『ERROR! The server quit without updating PID file』と表示される。
MySQLが起動できない
HomebrewでインストールしたMySQL5.7を起動しようとすると以下のエラーが表示される。
% mysql.server start Starting MySQL . ERROR! The server quit without updating PID file (/usr/local/var/mysql/xxxxx.local.pid).解決策
MySQLを一度アンインストールして
/usr/local/var/mysql
内のファイルを全削除した後、再インストールする。% brew uninstall mysql@5.7 % cd /usr/local/var/mysql # カレントディレクトリ内(/usr/local/var/mysql)の全フォルダとファイルを削除します。 % rm -rf * % brew install mysql@5.7以下のように表示されれば成功。
% mysql.server start Starting MySQL . SUCCESS!原因
MySQLの他のバージョンを使っていたために、ファイルの競合が起こっていた模様。
参考にさせていただいた記事
「ERROR! The server quit without updating PID file」となり、MacOSでmysqlにアクセスできない。
https://qiita.com/furafura_nau/items/7d8f5370899df125d459
- 投稿日:2020-01-16T05:05:33+09:00
Homebrew総集編
Homebrew
インストール
Terminalwebmaster-patche-no-MacBook-Pro:~ webmaster-patche$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ==> This script will install: /usr/local/bin/brew /usr/local/share/doc/homebrew /usr/local/share/man/man1/brew.1 /usr/local/share/zsh/site-functions/_brew /usr/local/etc/bash_completion.d/brew /usr/local/Homebrew Press RETURN to continue or any other key to abort ==> Downloading and installing Homebrew... remote: Enumerating objects: 181, done. remote: Counting objects: 100% (181/181), done. remote: Compressing objects: 100% (3/3), done. remote: Total 282 (delta 178), reused 179 (delta 178), pack-reused 101 Receiving objects: 100% (282/282), 77.69 KiB | 137.00 KiB/s, done. Resolving deltas: 100% (202/202), completed with 55 local objects. From https://github.com/Homebrew/brew c0b916764..8398d0b2d master -> origin/master HEAD is now at 8398d0b2d Merge pull request #6937 from MikeMcQuaid/bottle_sudo_non_interactive Updated 1 tap (homebrew/core). ==> New Formulae ansible@2.8 bandwhich cobalt findomain glow libb64 poetry awscurl cgns dsvpn git-filter-repo komposition nauty yaegi ==> Updated Formulae abcmidi fonttools mailutils prometheus ack fpp makedepend proteinortho acpica freetds man-db pstoedit algernon frpc mariadb puzzles aliyun-cli frps mariadb@10.2 pwntools alpine fselect mariadb@10.3 pyenv ammonite-repl fuse-zip mat2 pyinstaller angular-cli fx mawk pypy ansible gatsby-cli maxwell pypy3 ansible-lint gcsfuse mbedtls python-yq apache-opennlp gdb mda-lv2 quickjs apachetop ghq mdcat ranger appium gimme-aws-creds mdds rav1e aptly git mercurial rawtoaces arangodb git-lfs mesa remind arduino-cli git-plus meson rex artifactory git-quick-stats metaproxy rhino asciinema git-remote-hg mg rocksdb ask-cli git-review micropython roswell assimp gitbucket midnight-commander rsyslog astrometry-net gitleaks mill rtv atdtool gitmoji miller run atlassian-cli gjs minio rustup-init aws-cdk glassfish minio-mc s3cmd aws-elasticbeanstalk glib-networking mitmproxy saxon aws-shell global mk-configure scipy awscli glslang mkl-dnn serverless azure-cli gmsh mmark sflowtool babel gnunet mpc shadowsocks-libev balena-cli gnuradio mpd shfmt basex go mpop signal-cli bcftools go@1.12 mrboom silk bindfs godep mruby singular bit golang-migrate multimarkdown siril bitrise goreleaser multitail snapcraft blast gr-osmosdr mupdf socat botan grep mupdf-tools sonobuoy broot grin mutt sourcekitten caffe grin-wallet mycli sphinx-doc cake groonga mydumper spin ccache handbrake mypy starship cdk helmfile mysql statik cereal helmsman mysql@5.6 stormssh certbot help2man mysql@5.7 streamlink certigo hlint nano stress-ng cfn-lint homebank neo4j subversion chakra howdoi nethack svtplay-dl choose htslib netlify-cli swagger-codegen chronograf http-server nift swagger-codegen@2 codemod httpie node swiftformat cointop hugo node-build swiftlint collectd icecast node@10 syncthing conan ilmbase node@12 synfig conjure-up imagemagick nodeenv talloc consul-template imagemagick@6 now-cli tarantool contentful-cli imgproxy nss taskell convox interactive-rebase-tool ntl telegraf cpl internetarchive nuget teleport cppad istioctl numpy terraform cromwell jdupes nushell terragrunt csvq jenkins ocrmypdf terrahub ctl jfrog-cli-go offlineimap texmath ctop juju-wait okteto tintin curl k3d onefetch tmuxinator curl-openssl kcov opa tmuxinator-completion deno kepubify opencv tomee-jax-rs devspace kind opencv@2 tomee-plume dfmt kubeprod opencv@3 topgrade dhall kustomize openexr tox dhall-json kyma-cli openimageio trader distcc languagetool opensc traefik dmd lazygit openvdb tunnel docfx ldc operator-sdk twoping docker-compose lego osc twtxt docker-credential-helper-ecr leptonica pagmo txr docker-squash lerna paket uhd doctl lftp pandoc ultralist dovecot libarchive pcb urh dub libedit pcsc-lite verilator duck libetonyek pdsh vim dune libfabric peco vips duplicity libimagequant percol visp easyengine liblouis perl wal2json ejdb libmpdclient perltidy watch embree libofx pgcli wcslib entr libopenmpt pgweb webp envconsul librealsense phpmd weechat erlang libsixel phpmyadmin whois exploitdb libtensorflow phpstan wiggle fades libtorrent-rasterbar phpunit wireguard-tools fail2ban libuv picard-tools wla-dx fastlane libvirt picat wtf faudio libvirt-glib pipenv wxmaxima fdroidserver libvoikko pipx xdotool feedgnuplot libvterm plank xmrig ffsend libwebsockets pnpm xsimd field3d libxkbcommon pony-stable xtensor firebase-cli libxlsxwriter pre-commit yamllint flow liquibase prestodb ykman fluent-bit log4cplus primesieve yle-dl fluxctl logtalk procs you-get fn mafft proguard zsh-autosuggestions folly magic-wormhole proj ==> Deleted Formulae apel diffuse leafnode np2 pygtksourceview terminator zim auto-scaling globus-toolkit libagar pygobject qriollo trr aws-elasticache hg-flow mysql-utilities pygtk redo uberftp aws-sns-cli ipython@5 node@8 pygtkglext srclib vte ==> Installation successful! ==> Homebrew has enabled anonymous aggregate formulae and cask analytics. Read the analytics documentation (and how to opt-out) here: https://docs.brew.sh/Analytics ==> Homebrew is run entirely by unpaid volunteers. Please consider donating: https://github.com/Homebrew/brew#donations ==> Next steps: - Run `brew help` to get started - Further documentation: https://docs.brew.shバージョンの確認
Terminalwebmaster-patche-no-MacBook-Pro:~ webmaster-patche$ brew -v Homebrew 2.2.2 Homebrew/homebrew-core (git revision f246; last commit 2020-01-14)使い方
brew [--version | -v]
Terminal$ brew -v Homebrew 2.2.2 Homebrew/homebrew-core (git revision f246; last commit 2020-01-14) Homebrew/homebrew-cask (git revision 7585; last commit 2020-01-15) $ brew --version Homebrew 2.2.2 Homebrew/homebrew-core (git revision f246; last commit 2020-01-14) Homebrew/homebrew-cask (git revision 7585; last commit 2020-01-15)brew command [--verbose | -v] [options] [formula]…
command
- install / uninstall / list / search コマンドは必須コマンドとして他のコマンドとは異なる
install formula
- フォーミュラ(パッケージ名)をインストールします
- --verbose / --debug:デバッグ情報を出力
Terminaluninstall formula
- フォーミュラ(パッケージ名)をアンインストールします
Terminallist
- インストール済みのフォーミュラ(パッケージ名)をリスト出力します
Terminal$ brew list
search (text|/text/)
- テキストを使用してフォーミュラ(パッケージ名)を部分検索します
- スラッシュで挟まれている場合は正規表現として解釈する
検索する文字列はオンライン上でhomebrew / coreとhomebrew / caskによって行われる
参考になった技術まとめ
analytics [subcommand]
用途調査中
- on / off:Homebrewの分析をオンオフにする
- state:現在の匿名ユーザーの行動分析状態を表示、Analytics参照
- regenerate-uuid:Homebrewの分析で使用されるUUIDを再生成
cat formula
- フォーミュラ(パッケージ名)のソースを表示
cleanup [options] [formula|cask]
すべてのフォーミュラ(パッケージ名)とcaskの、古いロックファイルと古いダウンロードを削除し、インストールされたフォーミュラ(パッケージ名)の古いバージョンを削除
- --prune:指定された日より古いすべてのキャッシュファイルを削除する。
- -n / --dry-run:削除されるものを表示するだけで、実処理は行わない。(デバッグ実行)
- -s:最新バージョンのダウンロードも含め、キャッシュをスクラブする。インストールのためにダウンロードされたフォーミュラ(パッケージ名)や caskは削除されない。削除したい場合:
rm -rf "$(brew --cache)"
を行う- --prune-prefix:プレフィックスからシンボリックリンクとディレクトリのみを削除し、他のファイルを削除しません。
- command | cmd:brew cmdを呼び出すときに使用されているファイルへのパスを表示します。
Terminal$ brew cleanup --dry-run $commands [options]
- 組み込みコマンドと外部コマンド(
command項目を参照
)の一覧を表示する
- -q、-quiet:カテゴリヘッダーのない(組み込みコマンド、外部コマンドなど)コマンドの名前のみを一覧表示
- --include-aliases:内部コマンドのエイリアスを含める(-qオプションなしでは指定不可)
Terminal$ brew commands ==> Built-in commands --cache cask desc info missing search tap-pin update --cellar cat diy install options sh tap-unpin update-report --env cleanup doctor leaves outdated shellenv uninstall update-reset --prefix command fetch link pin style unlink upgrade --repository commands gist-logs list postinstall switch unpack uses --version config help log readall tap unpin vendor-install analytics deps home migrate reinstall tap-info untap ==> Built-in developer commands audit create install-bundler-gems mirror ruby update-test bottle edit irb prof tap-new vendor-gems bump-formula-pr extract linkage pull test bump-revision formula man release-notes tests ==> External commands aspell-dictionaries postgresql-upgrade-database services $ brew commands --include-aliases Error: `include_aliases` cannot be passed without `quiet`. $ brew commands -q --include-aliases --cache create ln style --cellar deps log switch --config desc ls tap --env diy man tap-info --prefix doctor migrate tap-new --repo dr mirror tap-pin --repository edit missing tap-unpin --version environment options test -S extract outdated tests -v fetch pin uninstal abv formula postgresql-upgrade-database uninstall analytics gist-logs postinstall unlink aspell-dictionaries help prof unpack audit home pull unpin bottle homepage readall untap bump-formula-pr info reinstall up bump-revision instal release-notes update cask install remove update-report cat install-bundler-gems rm update-reset cleanup irb ruby update-test command leaves search upgrade commands link services uses config linkage sh vendor-gems configure list shellenv vendor-installconfig
- Homebrewとシステム構成情報を表示してくれる
- バグレポートを提出する場合、この情報を提供する必要がある(Homebrewへの情報提供の場合)
Terminal$ brew --config HOMEBREW_VERSION: 2.2.2 ORIGIN: https://github.com/Homebrew/brew HEAD: 13f508d0dc8ada1726ee09a750285d7447ac3df4 Last commit: 3 weeks ago Core tap ORIGIN: https://github.com/Homebrew/homebrew-core Core tap HEAD: f2463cbba086689c872cddd3a8bc242976a603ff Core tap last commit: 20 hours ago HOMEBREW_PREFIX: /usr/local CPU: octa-core 64-bit ivybridge Homebrew Ruby: 2.6.3 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3/bin/ruby Clang: 10.0 build 1001 Git: 2.20.1 => /Library/Developer/CommandLineTools/usr/bin/git Curl: 7.54.0 => /usr/bin/curl macOS: 10.14.6-x86_64 CLT: 10.3.0.0.1.1562985497 Xcode: N/A $ brew config HOMEBREW_VERSION: 2.2.2 ORIGIN: https://github.com/Homebrew/brew HEAD: 13f508d0dc8ada1726ee09a750285d7447ac3df4 Last commit: 3 weeks ago Core tap ORIGIN: https://github.com/Homebrew/homebrew-core Core tap HEAD: f2463cbba086689c872cddd3a8bc242976a603ff Core tap last commit: 20 hours ago HOMEBREW_PREFIX: /usr/local CPU: octa-core 64-bit ivybridge Homebrew Ruby: 2.6.3 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3/bin/ruby Clang: 10.0 build 1001 Git: 2.20.1 => /Library/Developer/CommandLineTools/usr/bin/git Curl: 7.54.0 => /usr/bin/curl macOS: 10.14.6-x86_64 CLT: 10.3.0.0.1.1562985497 Xcode: N/Adeps [options] [formula]
フォーミュラ(パッケージ名)の依存関係を表示
- -n:依存関係をトポロジー順にソートします。
- --1:再帰ではなく、1レベル下の依存関係のみを表示します。
- --union:交点ではなく、複数のフォーミュラ(パッケージ名)の依存関係の和集合を表示します。
- --full-name:依存関係をフルネームでリストします。
- --include-build:インクルード:フォーミュラ(パッケージ名)のビルド依存関係。
- --include-optional:Include:フォーミュラ(パッケージ名)のオプションの依存関係。
- --include-test:フォーミュラ(パッケージ名)の:test依存関係を含めます(非再帰的)。
- --skip-recommended:フォーミュラ(パッケージ名)の推奨依存関係をスキップします。
- --include-requirements:フォーミュラ(パッケージ名)の依存関係に加えて要件を含めます。
- --tree:依存関係をツリーとして表示します。複数のフォーミュラ(パッケージ名)引数を指定した場合、各フォーミュラ(パッケージ名)の個別のツリーを表示します。
- --annotate:ビルド、テスト、オプション、または推奨される依存関係を出力でマークします。
- --installed:現在インストールされているフォーミュラ(パッケージ名)の依存関係を一覧表示します。フォーミュラ(パッケージ名)が指定されている場合、現在インストールされている依存関係のみをリストします。
- --all:使用可能なすべての式の依存関係を一覧表示します。
- --for-each:--allオプションで使用されるモードに切り替えますが、指定された各式の依存関係のみをリストします(1行に1つの式)。これは、-installed / -all表示モードのデバッグに使用されます。
Terminal$ brew deps vim gdbm libyaml openssl perl python readline ruby sqlite xz
- 参考になった技術まとめ
desc options
- フォーミュラ(パッケージ名)の名称と説明を表示する
なお表示する説明はキャッシュされ、後から表示したものに比べて検索速度が遅くなる(キャッシュが古くなる為)
- -s、-search:テキストの名前と説明の両方を検索します。テキストがスラッシュで挟まれている場合、それは正規表現として解釈されます。
- -n、--name:テキストの名前だけを検索します。テキストがスラッシュで挟まれている場合、それは正規表現として解釈されます。
- -d、-description:テキストの説明だけを検索します。テキストがスラッシュで挟まれている場合、それは正規表現として解釈されます。
- diy [オプション]:非Homebrewソフトウェアのインストールプレフィックスを自動的に決定します。このコマンドの出力を使用して、独自のソフトウェアをセラーにインストールしてから、brewリンクを使用してHomebrewのプレフィックスにリンクできます。
- --name:インストールするパッケージの名前を明示的に設定します。
- --version:インストールするパッケージのバージョンを明示的に設定します。
doctor [options]
- システムに潜在的な問題がないか確認する
- 潜在的な問題が見つかった場合、ゼロ以外のステータスで終了
Terminal$ brew doctor Your system is ready to brew. $ echo $? 0 # -> エラーがある場合、異常終了すると思われるupgrade [options]
- Homebrew のパッケージの更新(サブコマンド)
- 30日以上古いものが自動削除される
- 自動削除を止めたければ、環境変数
env HOMEBREW_INSTALL_CLEANUP=1
で止めるTerminal# デフォルト(30日以上古いものを自動削除) $ brew upgrade # 自動削除しない場合 $ env HOMEBREW_INSTALL_CLEANUP=1 brew upgradeupdate
- deplicated
拡張機能
Homebrew cask
インストール
Terminal$ brew cask ==> Tapping homebrew/cask Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'... remote: Enumerating objects: 3624, done. remote: Counting objects: 100% (3624/3624), done. remote: Compressing objects: 100% (3616/3616), done. remote: Total 3624 (delta 25), reused 545 (delta 6), pack-reused 0 Receiving objects: 100% (3624/3624), 1.22 MiB | 1.49 MiB/s, done. Resolving deltas: 100% (25/25), done. Checking out files: 100% (3604/3604), done. Tapped 1 command and 3512 casks (3,629 files, 3.9MB). Homebrew Cask provides a friendly CLI workflow for the administration of macOS applications distributed as binaries. Commands: --cache display the file used to cache the Cask audit verifies installability of Casks cat dump raw source of the given Cask to the standard output create creates the given Cask and opens it in an editor doctor checks for configuration issues edit edits the given Cask fetch downloads remote application files to local cache home opens the homepage of the given Cask info displays information about the given Cask install installs the given Cask list with no args, lists installed Casks; given installed Casks, lists staged files outdated list the outdated installed Casks reinstall reinstalls the given Cask style checks Cask style using RuboCop uninstall uninstalls the given Cask upgrade upgrades all outdated casks zap zaps all files associated with the given Cask See also "man brew-cask"使い方
- インストール時に表示されるCommandsを参照
cask [subcommand]
- install [cask]
- cask をインストールします
Terminal$ brew cask install google-chromeHomebrew services
インストール
Terminal$ brew services list ==> Tapping homebrew/services Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'... remote: Enumerating objects: 14, done. remote: Counting objects: 100% (14/14), done. remote: Compressing objects: 100% (9/9), done. remote: Total 14 (delta 0), reused 7 (delta 0), pack-reused 0 Unpacking objects: 100% (14/14), done. Tapped 1 command (43 files, 59.4KB). Warning: No services available to control with `brew services`これで自動で
tap
されてbrew services
が使用可能な状態になりますTerminal$ brew services list Name Status User Plist mysql@5.7 stopped
使い方
services list
- serviceの一覧を表示
services start formula
- フォーミュラ(パッケージ名) を開始、かつ、ログイン時に起動する設定をする
services stop formula
- フォーミュラ(パッケージ名) を停止、かつ、ログイン時に起動する設定を消す
services restart formula
- フォーミュラ(パッケージ名) でstop; startを実行
Terminal$ brew services start mysql@5.7 ==> Successfully started `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)
- 参考になった技術まとめ
最後に
- brewのバージョンアップデートや拡張機能で変化が激しい為、このまとめは随時編集されます
- 投稿日:2020-01-16T02:53:41+09:00
heroku 登録から(rails mysql)デプロイまで
ローカルでは動作確認済みのRailsアプリを、heroku初デプロイ
環境
- heroku
- MacBookpro
- ruby 2.6.3
- bundrer 2.0.2
- rails 6.0.1
- Mysql2 0.5.3
- GitHub にて git clone(もしくは push) してある状態
<今後の時短のために記録> 今回Qiita自己用記録も含め、10時間かかった様子。
他でデプロイに14日かけてうまく行かず...原因がMVCではない事を再認識できた。知識不足、書籍等を活用する予定。
heroku1日で出来るのは有難い。
①heroku にアカウント登録
https://jp.heroku.com/<<AWS と違い、基本ローカルからコマンド 入力 >>
②config/routes.rbのindex編集
Rails.application.routes.draw do resources :blogs root 'home#top' #トップページ:homeコントローラのtopアクションに設定gem mysql (の確認。今回はローカルから記入済みなので、もし変更したらbundle install)
$ git add . $ git commit $ git push origin master (GitHubへ)
次回以降のapp作成時は ④$ heroku login へ
③herokuのインストール
~~$ brew tap heroku/brew && brew install heroku~~ ここ保留 $ heroku -v(ersion) 確認④$ heroku login のため sshキー設定 <④は省略内容にはなる為 他サイト参考必須>
(ローカルの.ssh に移動) $ ssh-keygen -t rsa:作成したいキー名_rsa
ls確認。$ eval "$(ssh-agent -s)"cd デプロイ先の階層に戻る
$ heroku keys:add ~/.ssh/作成した_rsa.pub........SSH key... done で成功。
$ heroku keys で確認可 *キーはherokuのHPでも確認可
⑤
$ heroku create (herokuのHPで作成したアプリ名)**or
$ git remote heroku (herokuのHPで作成したいアプリ名)Name (作成したいアプリ名) is already taken。。。 で作成された
<<< $ git remote -v
origin
origin git@github.com:。。。。。。。(GitHubのしかないため、リモート:herokuを設定。アプリ名を指定しないとherokuリモートは自動で
作成される様子。)$ heroku git:remote -a (作成したアプリ名)
set git remote heroku to https://git.heroku.com/(作成したアプリ名) と出る
$ git remote -v で確認。 heroku origin>>>
⑥ DB設定
< [公式heroku参考] https://elements.heroku.com/addons/cleardb >$ heroku create cleardb:ignite Please verify your account to install this add-on plan (please enter a credit card) For more ▸ information, see https://devcenter.heroku.com/categories/billing Verify now at ▸ https://heroku.com/verifyheroku hpにてクレカの登録
2回目アプリデプロイ時、
Name must start with a letter, end with a letter or digit and can only
▸ contain lowercase letters, digits, and dashes.と出た為、HPでアドオン DBFree設定した。 = ⑦へ
⑦環境変数の設定
$ heroku config ($ git config --list)で内容確認) > CLEARDB_DATABASE_URL: mysql://<ユーザー名>:<パスワード>@<ホスト名>/<データベース名>?reconnect=true$ heroku config:add DB_NAME='<データベース名>' $ heroku config:add DB_USERNAME='<ユーザー名>' $ heroku config:add DB_PASSWORD='<パスワード>' $ heroku config:add DB_HOSTNAME='<ホスト名>' $ heroku config:add DB_PORT='3306' $ heroku config:add DATABASE_URL='mysql2://<ユーザー名>:<パスワード>@<ホスト名>/<データベース名>?reconnect=true'$ heroku config で設定内容 再確認
⑧ config/environments/production.rb を記入
config/environments/production.rbconfig.assets.compile = true config.assets.initialize_on_precompile=false<herokuへpush>
$ git add . $ git commit $ git push heroku master
⑨database.yml 設定
変更)production: <<: *default database: [データベース名] username: [ユーザ名] password: <%= ENV['DATABASE_PASSWORD'] %>
(10) herokuのDBのマイグレーション
$ heroku rake db:migrate $ heroku openremote: Verifying deploy... done. 成功。
[上のURLの方。ターミナ下方のURLではない。
https://(各自)...herokuapp.com/ (← これ => deployed to Heroku ]<urlに接続>
<ログを表示>
$ heroku logs (heroku logs --tail) ↑ 見ても原因が良くわからない為 ↓で今回はエラー解決した$ heroku run rails console の方が分かる
<urlに接続したが、エラーindex.htmlに繋がる。>
ここからエラー内容3回目
$ heroku restart 一応。 (firebaseデプロイ時は時差があった、が変わらず。) $ heroku logs --tail内容が分からず、
$ heroku run rails console で原因が分かりやすい。 Could not load the 'mysql' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile. (LoadError)ここで、Gemfile に合わせ mysql → mysql2 に変更した。
デプロイ成功
②config/routes.rbで指定したindex.htmlが表示された。
ここから↓ git push heroku master成功までの
実際のエラー対処記載 一部を参考に残す。
⑨ ←ここでエラー内容1回目
Could not load the 'mysql' A....database.yml も確認しろと出る。database.yml 確認修正↓
⑦の $ heroku config:add DATABASE_URL='mysql2://<ユーザー名>:<パスワード>@<ホスト名>/<データベース名>?reconnect=true'
を Gemfile に合わせ mysql → mysql2 に最終的に変更。かつ bundle install
エラー内容2回目
... Could not detect rake tasks remote: ! ensure you can run `$ bundle exec rake -P` ...URI::InvalidURIError: bad URI(is not URI?): mysql2:....$ rbenv -v rbenv 1.1.2 $ ruby -v ruby '2.6.4' $ gem install bundler -v 2.0.2 $ bundle install( + update) $ rbenv -v が1.1.2のままの為、 $ rm Gemfile.lock $ bundle install でGemfile.lock 再 bundler -v 2.0.2へ。 (add . commit ) $ git push heroku master 変わらず同エラー。 今回は公式サイトを参考に、 ruby '2.6.3'に下げる。 $ rbenv install 2.6.3 $ rbenv local 2.6.3 (Gemfileも変更。$ bundle install $ rbenv rehash) 変わらず同エラー。 $ heroku config 設定ミスか確認。 $ heroku config:add DATABASE_URL='mysql://...をmysql2:... に変更。 変わらず同エラー。 <直接な解決なのかは不明だが、今回は、$ heroku create アプリ名を指定しないで再度やり直す。このエラーは解決> $ heroku create $ git remote で自動herokuリモートが作成された。 $ git push heroku masterbad URI(is not URI?): mysql2:...エラーは解決したが、
新たなエラー1回目remote: ! remote: ! Precompiling assets failed.Precompil なので、
config/application.rbに config.assets.initialize_on_precompile = true を追記。 config/environments/production.rbの onfig.assets.compile = false を trueに。 変わらず。 $ RAILS_ENV=production (bundle exec) rake assets:precompile 変わらず。webpacker.yml .gitignore の編集で解決した。
webpacker.yml 内に
production:
<<: *default
compile: true がある為と思われる。全て知識不足が原因。
実際には③で 小さいエラーが出て bundle update install 等をプラス作業した
その後、push。<基本だが一応残す>
rails -v ruby -v mysql -v 。。。ローカルの諸々の確認はした前提の内容。
③で
...Warning: heroku update available from 7.35.0 to 7.35.1..... $ heroku uodate を実行。 $ heroku -v 確認
⑨ mysql2 エラー
($ brew update && brew upgrade ruby-build できなかった)
GitHub 接続確認
$ ssh -T github git@github.com
他サーバーにて設定変更してしまった為今回 再設定。
参考にしたサイト
mysqlを使ったRailsアプリをHerokuにデプロイする流れ
追えなくなってしまいましたが、その他、多々多々参考にさせて頂きました。
herokuチュートリアル
一部コマンドが公式の方が新しい様子です...
- 投稿日:2020-01-16T00:55:31+09:00
Mac でデフォルト NIC のプライベート IP アドレス を調べる方法
デフォルトの NIC を調べる
有線 LAN と無線を同時接続している時など、複数 NIC がある場合、まずはデフォルトの NIC の名前を特定する必要があります。
DEFAULT_INTERFACE=`route -n get default | grep 'interface' | awk '{print $2}'` echo $DEFAULT_INTERFACENIC からプライベート IP アドレス を調べる
NIC 名がわかれば以下のコマンドで簡単に IP アドレスを調べられます。
DEFAULT_IP_ADDRESS=`ipconfig getifaddr $DEFAULT_INTERFACE` echo $DEFAULT_IP_ADDRESSまとめ
.zshrc とかに仕込んどくと便利かもしれません。
echo 'DEFAULT_INTERFACE=`route -n get default | grep '"'"'interface'"'"' | awk '"'"'{print $2}'"'"'`' >> ~/.zshrc echo 'DEFAULT_IP_ADDRESS=`ipconfig getifaddr $DEFAULT_INTERFACE`' >> ~/.zshrc