Last active
April 10, 2017 03:10
-
-
Save yusuke-konishi/cc67b17a9b3c5e4d4c63e07f93934bae to your computer and use it in GitHub Desktop.
Bash on Ubuntu on Windows で Rails/PostgreSQL の開発環境を構築する [Anniversary Update 編] ref: http://qiita.com/yusuke_konishi/items/80d8a89b83ce17718f76
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
passwd: password updated successfully | |
インストールが正常に終了しました | |
環境が間もなく開始されます... | |
ドキュメントを参照できる場所: https://aka.ms/wsldocs | |
bowuser@BOWHOST:/mnt/c/Users/winuser$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo sed -i -e "/127.0.0.1 localhost/s/$/ $(hostname)/g" /etc/hosts | |
sudo: ホスト BOWHOST の名前解決ができません | |
[sudo] password for bowuser: (パスワードを入力) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo update-locale LANG=en_US.UTF-8 | |
$ source /etc/default/locale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo sed -i -e 's/archive/jp.archive/g' /etc/apt/sources.list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ echo 'umask 022' >> ~/.bashrc | |
$ source ~/.bashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkdir /mnt/c/workspace | |
$ ln -s /mnt/c/workspace ~/workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo apt-get update | |
$ sudo apt-get upgrade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo apt-get install git nodejs build-essential libreadline-dev libyaml-dev libxslt-dev libcurl4-openssl-dev libffi-dev sqlite3 libsqlite3-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv | |
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc | |
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc | |
$ source ~/.bashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build | |
$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc | |
$ source ~/.bashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name DontUsePowerShellOnWinX -PropertyType DWord -Value 0 -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rbenv install 2.3.0 | |
$ rbenv global 2.3.0 | |
$ ruby -v | |
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ echo 'gem: --no-document' >> ~/.gemrc | |
$ gem install bundler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' | |
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - | |
$ sudo apt-get update | |
$ sudo apt-get install postgresql-client-9.5 libpq-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ exit | |
> Start-BitsTransfer -Source http://get.enterprisedb.com/postgresql/postgresql-9.5.5-1-windows-x64.exe -Destination C:\workspace\postgresql-9.5.5-1-windows-x64.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> C:\workspace\postgresql-9.5.5-1-windows-x64.exe --mode unattended --superpassword <postgres ユーザーのパスワード> --locale C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ psql -h localhost -U postgres | |
Password for user postgres: (postgres ユーザーのパスワードを入力) | |
psql (9.5.5) | |
Type "help" for help. | |
postgres=# \q |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ echo 'export PGHOST=localhost' >> ~/.bashrc | |
$ source ~/.bashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ createuser $(whoami) -s -U postgres | |
Password: (postgres ユーザーのパスワードを入力) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sed -i -e '/^host/s/md5/trust/g' /mnt/c/Program\ Files/PostgreSQL/9.5/data/pg_hba.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Stop-Process -Name explorer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd ~/workspace | |
$ gem install rails -v 4.2.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rails _4.2.3_ new bowapp -d postgresql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd bowapp | |
$ bundle config --delete bin | |
$ rake rails:update:bin | |
Expected string default value for '--rc'; got false (boolean) | |
exist bin | |
identical bin/bundle | |
conflict bin/rails | |
Overwrite /mnt/c/workspace/bowapp/bin/rails? (enter "h" for help) [Ynaqdh] a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rails generate scaffold surfboard model:string shaper:string company:string | |
$ rake db:create db:migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rake routes | |
Prefix Verb URI Pattern Controller#Action | |
surfboards GET /surfboards(.:format) surfboards#index | |
POST /surfboards(.:format) surfboards#create | |
new_surfboard GET /surfboards/new(.:format) surfboards#new | |
edit_surfboard GET /surfboards/:id/edit(.:format) surfboards#edit | |
surfboard GET /surfboards/:id(.:format) surfboards#show | |
PATCH /surfboards/:id(.:format) surfboards#update | |
PUT /surfboards/:id(.:format) surfboards#update | |
DELETE /surfboards/:id(.:format) surfboards#destroy | |
$ rails s | |
=> Booting WEBrick | |
=> Rails 4.2.3 application starting in development on http://localhost:3000 | |
=> Run `rails server -h` for more startup options | |
=> Ctrl-C to shutdown server | |
[2016-12-20 00:15:34] INFO WEBrick 1.3.1 | |
[2016-12-20 00:15:34] INFO ruby 2.3.0 (2015-12-25) [x86_64-linux] | |
[2016-12-20 00:15:34] INFO WEBrick::HTTPServer#start: pid=13342 port=3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rails c | |
Loading development environment (Rails 4.2.3) | |
irb(main):001:0> Surfboard.all | |
Surfboard Load (0.7ms) SELECT "surfboards".* FROM "surfboards" | |
=> #<ActiveRecord::Relation [#<Surfboard id: 1, model: "Sci-Fi", shaper: "ダニエル・トムソン", company: "Firewire Surfboards", created_at: "2016-12-19 15:22:26", updated_at: "2016-12-19 15:22:26">]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gem install bundler | |
Fetching: bundler-1.13.6.gem (100%) | |
/home/bowuser/.rbenv/rbenv.d/exec/gem-rehash/rubygems_plugin.rb:6: warning: Insecure world writable dir /home/bowuser/.rbenv/versions in PATH, mode 040777 | |
Successfully installed bundler-1.13.6 | |
1 gem installed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ umask | |
0000 | |
$ echo 'umask 022' >> ~/.bashrc | |
$ source ~/.bashrc | |
$ umask | |
0022 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ chmod -R go-w ~/.rbenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo apt-get install postgresql-9.5 libpq-dev | |
... | |
Setting up postgresql-9.5 (9.5.5-1.pgdg14.04+1) ... | |
Creating new cluster 9.5/main ... | |
config /etc/postgresql/9.5/main | |
data /var/lib/postgresql/9.5/main | |
locale en_US.UTF-8 | |
FATAL: could not create shared memory segment: Function not implemented | |
DETAIL: Failed system call was shmget(key=1, size=56, 03600). | |
child process exited with exit code 1 | |
initdb: removing contents of data directory "/var/lib/postgresql/9.5/main" | |
Error: initdb failed | |
Error: could not create default cluster. Please create it manually with | |
pg_createcluster 9.5 main --start | |
or a similar command (see 'man pg_createcluster'). | |
update-alternatives: using /usr/share/postgresql/9.5/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode | |
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused | |
runlevel:/var/run/utmp: No such file or directory | |
invoke-rc.d: policy-rc.d denied execution of start. | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock -Name AllowAllTrustedApps -PropertyType DWord -Value 1 -Force | |
> New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock -Name AllowDevelopmentWithoutDevLicense -PropertyType DWord -Value 1 -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gem::Ext::BuildError: ERROR: Failed to build gem native extension. | |
current directory: | |
/home/bowuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/debug_inspector-0.0.2/ext/debug_inspector | |
/home/bowuser/.rbenv/versions/2.3.0/bin/ruby -r ./siteconf20161215-200-qnw3kc.rb | |
extconf.rb | |
Cannot allocate memory - /home/bowuser/.rbenv/versions/2.3.0/bin/ruby -r | |
./siteconf20161215-200-qnw3kc.rb extconf.rb 2>&1 | |
Gem files will remain installed in | |
/home/bowuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/debug_inspector-0.0.2 | |
for inspection. | |
Results logged to | |
/home/bowuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/debug_inspector-0.0.2/gem_make.out | |
An error occurred while installing debug_inspector (0.0.2), and Bundler cannot | |
continue. | |
Make sure that `gem install debug_inspector -v '0.0.2'` succeeds before | |
bundling. | |
run bundle exec spring binstub --all | |
bundler: command not found: spring | |
Install missing gem executables with `bundle install` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rails generate scaffold surfboard model:string shaper:string company:string | |
Version: 2.0.0 | |
Usage: spring COMMAND [ARGS] | |
Commands for spring itself: | |
binstub Generate spring based binstubs. Use --all to generate a binstub for all known commands. Use --remove to revert. | |
help Print available commands. | |
server Explicitly start a Spring server in the foreground | |
status Show current status. | |
stop Stop all spring processes for this project. | |
Commands for your application: | |
rails Run a rails command. The following sub commands will use spring: console, runner, generate, destroy, test. | |
rake Runs the rake command | |
Error: Command 'rails' not recognized | |
Usage: rails COMMAND [ARGS] | |
The most common rails commands are: | |
generate Generate new code (short-cut alias: "g") | |
console Start the Rails console (short-cut alias: "c") | |
server Start the Rails server (short-cut alias: "s") | |
dbconsole Start a console for the database specified in config/database.yml | |
(short-cut alias: "db") | |
new Create a new Rails application. "rails new my_app" creates a | |
new application called MyApp in "./my_app" | |
In addition to those, there are: | |
destroy Undo code generated with "generate" (short-cut alias: "d") | |
plugin new Generates skeleton for developing a Rails plugin | |
runner Run a piece of code in the application environment (short-cut alias: "r") | |
All commands can be run with -h (or --help) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bundle config --delete bin | |
$ rake rails:update:bin | |
Expected string default value for '--rc'; got false (boolean) | |
exist bin | |
identical bin/bundle | |
conflict bin/rails | |
Overwrite /mnt/c/workspace/bowapp/bin/rails? (enter "h" for help) [Ynaqdh] a | |
force bin/rails | |
conflict bin/rake | |
force bin/rake | |
identical bin/setup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git add bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> lxrun /uninstall /full /y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> C:\Program` Files\PostgreSQL\9.5\uninstall-postgresql.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Remove-Item -Path 'C:\Program Files\PostgreSQL' -Recurse -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Remove-Item -Path C:\workspace -Recurse -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux | |
この操作を完了するために、今すぐコンピューターを再起動しますか? | |
[Y] Yes [N] No [?] ヘルプ (既定値は "Y"): Y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ベータ機能 -- | |
これにより Windows に Ubuntu がインストールされます。Ubuntu は Canonical によって配布される製品であり、 | |
次のサイトに示される条件に基づいてライセンスされています。 | |
https://aka.ms/uowterms | |
続行するには、"y" を入力してください: y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows ストアからダウンロードしています... 100% | |
ファイル システムを展開しています。この処理には数分かかります... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
既定の UNIX ユーザー アカウントを作成してください。ユーザー名は、Windows のユーザー名と一致する必要はありません。 | |
詳細: https://aka.ms/wslusers を参照してください | |
新しい UNIX ユーザー名を入力してください: bowuser | |
新しい UNIX パスワードを入力してください: (パスワードを入力) | |
新しい UNIX パスワードを再入力してください: (パスワードを再入力) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment