Setup Rails on Ruby in ubuntu
Setup Rails on Ruby develop environment in ubuntu
setup proxy
use %5C instead of \
change <domainshortname> <username> <password> <proxyhost> <proxyport>
into real value
if your proxy doesn’t need auth, remove the auth parts: <domainshortname>%5C<username>:<password>@
$ sudo vi /etc/environment
export HTTP_PROXY="http://<domainshortname>%5C<username>:<password>@<proxyhost>:<proxyport>"
export HTTPS_PROXY="http://<domainshortname>%5C<username>:<password>@<proxyhost>:<proxyport>"
$ sudo vi /etc/apt/apt.conf
Acquire::http::Proxy "http://<domainshortname>%5C<username>:<password>@<proxyhost>:<proxyport>";
Acquire::https::Proxy "http://<domainshortname>%5C<username>:<password>@<proxyhost>:<proxyport>";
$ sudo vi /etc/wgetrc
http_proxy=http://<domainshortname>%5C<username>:<password>@<proxyhost>:<proxyport>
https_proxy=http://<domainshortname>%5C<username>:<password>@<proxyhost>:<proxyport>
$ vi $HOME/.bashrc
export http_proxy=http://<domainshortname>%5C<username>:<password>@<proxyhost>:<proxyport>
export https_proxy=${http_proxy}
$ vi $HOME/.curlrc
proxy = "http://<domainshortname>%5C<username>:<password>@<proxyhost>:<proxyport>"
$ exec $SHELL -l
install required dependencies
$ sudo apt update
$ sudo apt upgrade
$ sudo apt-get install -y git build-essential libssl-dev libssl-dev zlib1g-dev libsqlite3-dev libpq-dev nodejs npm libmagic-dev postgresql unzip xvfb libxi6 libgconf-2-4
config git
$ git config --global http.sslverify false
$ git config --global https.sslverify false
# this is needed for proxy auth
$ git config --global http.proxyauthmethod basic
$ git config --global credential.helper store
$ git config --global alias.co checkout
$ git config --global alias.ci commit
$ git config --global alias.bc branch
$ git config --global alias.st status
$ git config --global core.autocrlf false
set up ruby and rails
change <youlogin> to your real login
$ sudo git clone https://github.com/rbenv/rbenv.git /usr/local/rbenv
$ sudo git clone https://github.com/rbenv/ruby-build.git /usr/local/rbenv/plugins/ruby-build
$ cd /usr/local
$ sudo chgrp -R staff rbenv
$ sudo chmod -R g+rwxXs rbenv
$ sudo gpasswd -a <youlogin> staff
$ sudo vi /etc/profile.d/rbenv.sh
export RBENV_ROOT=/usr/local/rbenv
export PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)"
$ exec $SHELL -l
$ type rbenv
$ sudo vi /usr/local/rbenv/plugins/ruby-build/bin/ruby-build
# search http_head_curl and remove q
http_head_curl() {
curl -sILf "$1" >& 4 2 >& 1
}
#search http_get_curl and remove -q
http_get_curl() {
curl -o "${2:--}" -sSLf "$1"
}
# check the latest <version> of ruby
$ sudo -i rbenv install --list
$ sudo -i rbenv install <version>
$ sudo -i rbenv global <version>
$ rbenv versions
$ sudo -i gem install bundler --no-document
$ sudo -i gem install rails --no-document
$ ruby -v
$ rails -v
$ sudo -i gem install sqlite
update nodejs and install yarn
$ sudo npm install n -g
$ sudo n stable
$ sudo apt purge -y nodejs npm
$ exec $SHELL -l
$ node -v
$ sudo npm install yarn -g
$ yarn -v
Ruby on Rails Tutorial
$ cd ~/
$ mkdir environment
$ cd environment
$ rails new hello_app
$ cd hello_app
$ rails s -b 0.0.0.0 -p 3000
access http://localhost:3000 with web browser
press CTRL+c
to exit
Setup for RSpec
run rspec test
# Default: Run all spec files (i.e., those matching spec/**/*_spec.rb)
$ bundle exec rspec
# Run all spec files in a single directory (recursively)
$ bundle exec rspec spec/model
# Run a single spec file
$ bundle exec rspec spec/controllers/accounts_controller_spec.rb
# Run a single example from a spec file (by line number)
$ bundle exec rspec spec/controllers/accounts_controller_spec.rb:8
# See all options for running specs
$ bundle exec rspec --help
# run following commands under your project
$ rspec -o rspec.html -f h spec/models/ spec/requests/ > rspec-result.html
# you can check rspec result by opening rspec-result.html and coverage by opening coverage/index.html
Setup for dev
$ sudo snap set system proxy.http=http://<domainshortname>%5C<username>:<password>@<proxyhost>:<proxyport>
$ sudo snap set system proxy.https=http://<domainshortname>%5C<username>:<password>@<proxyhost>:<proxyport>
$ sudo snap install --classic code
$ code
after vscode opened, install Ruby/Rails Extensions.
Setup for debug
install ruby-debug-ide, debase
sudo -i gem install ruby-debug-ide debase
open code and then File -> Open Folder -> select the root folder of your project
File -> Preferences -> Setting
Search for launch
and click Edit in settings.json
input the following launch config:
{
"launch": {
"configurations": [{
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"pathToRDebugIDE": "/usr/local/rbenv/shims/rdebug-ide",
"showDebuggerOutput": true,
"args": [
"server",
"-b",
"0.0.0.0",
"-p",
"3001"
]
}]
}
}
click ‘Run and Debug’ icon in left Side bar click ‘run’ icon of ‘Rails server’: the debug console will be opened in the bottom area.