Настройка окружения для разработки на Ruby on Rails на Ubuntu 16.04 с нуля

28 августа 2017, понедельник

Установка git

Для начала установим и настроим git. Система контроля версий git устанавливается следующей командой:

sudo apt install git

И сконфигурируем:

git config --global user.email "ваша@почта.com"
git config --global user.name "Ваше имя"

Подробнее тут.

Установка PostgreSQL

Установим PostgreSQL следующими командами

sudo apt-get update
sudo apt-get install postgresql postgresql-contrib

Далее установим пароль юзеру postgres

sudo -u postgres psql postgres
postgres=# ALTER USER postgres PASSWORD 'newpassword';
postgres=# \q

Подробнее тут, тут и тут.

Установка RVM, Ruby и Rails

Установим RVM как в инструкции

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash

Далее Ruby:

\curl -sSL https://get.rvm.io | bash -s stable --ruby

при выполнении этой команды я получил ошибку

Downloading https://github.com/rvm/rvm/archive/1.29.2.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.2/1.29.2.tar.gz.asc
gpg: Signature made Чт 22 июн 2017 19:18:38 MSK using RSA key ID BF04FF17
gpg: Can't check signature: No public key
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).

GPG signature verification failed for '/home/et/.rvm/archives/rvm-1.29.2.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.2/1.29.2.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:

    gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -

the key can be compared with:

    https://rvm.io/mpapis.asc
    https://keybase.io/mpapis

NOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. Please downgrade or upgrade to newer version (if available) or use the second method described above.

Далее выполнил указанную команду:

gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

И еще раз попытался установить ruby:

\curl -sSL https://get.rvm.io | bash -s stable --ruby

Успешно.

Далее установим более новую версию ruby:

rvm install 2.4.1

И сделаем ее используемой по умолчанию:

rvm --default 2.4.1

А также установим rails:

\curl -sSL https://get.rvm.io | bash -s stable --rails

Можно создавать новый проект;

rails new your_project_name

Установка Rubymine

Делаем все как в интрукции

tar -xzf RubyMine-X.Y.Z.tar.gz

mkdir -p ~/bin/rubymines/
mkdir -p ~/bin/rubymine/

mv ~/Downloads/RubyMine-X.Y.Z ~/bin/rubymines

ln -nfs ~/bin/rubymines/RubyMine-X.Y.Z ~/bin/rubymine

cd ~/bin/rubymines/RubyMine-X.Y.Z/bin

sudo ./rubymine.sh

Далее создаем/открываем проект в rubymine и идем в меню Tools -> Create Desktop Entry

Установка Redis

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install redis-server
sudo systemctl enable redis-server.service

Установка Node и NPM:

Также по инструкции

sudo apt-get update
sudo apt-get install build-essential libssl-dev

curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh

nano install_nvm.sh

bash install_nvm.sh

source ~/.profile

nvm ls-remote
nvm install 7.7.3
nvm use 7.7.3

В основном все. По ходу установки гемов возникли различные проблемы, которые решались по мере поступления, например:

gem install curb error

gem install curb -v '0.9.3'

Fetching: curb-0.9.3.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing curb:
        ERROR: Failed to build gem native extension.

    current directory: /home/et/.rvm/gems/ruby-2.4.0/gems/curb-0.9.3/ext
/home/et/.rvm/rubies/ruby-2.4.0/bin/ruby -r ./siteconf20170829-5069-qlhfxj.rb extconf.rb
checking for curl-config... no
checking for -lcurl... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/et/.rvm/rubies/ruby-2.4.0/bin/$(RUBY_BASE_NAME)
        --with-curl-dir
        --without-curl-dir
        --with-curl-include
        --without-curl-include=${curl-dir}/include
        --with-curl-lib
        --without-curl-lib=${curl-dir}/lib
        --with-curllib
        --without-curllib
extconf.rb:18:in `<main>':   Can't find libcurl or curl/curl.h (RuntimeError)

  Try passing --with-curl-dir or --with-curl-lib and --with-curl-include
  options to extconf.

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/et/.rvm/gems/ruby-2.4.0/extensions/x86_64-linux/2.4.0/curb-0.9.3/mkmf.log

extconf failed, exit code 1
sudo apt-get install libcurl4-openssl-dev
gem install curb -v '0.9.3'
Building native extensions.  This could take a while...
Successfully installed curb-0.9.3
Parsing documentation for curb-0.9.3
Installing ri documentation for curb-0.9.3
Done installing documentation for curb after 0 seconds
1 gem installed

gem install libxml-ruby error

gem install libxml-ruby -v '3.0.0'
Fetching: libxml-ruby-3.0.0.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing libxml-ruby:
        ERROR: Failed to build gem native extension.

    current directory: /home/et/.rvm/gems/ruby-2.4.0/gems/libxml-ruby-3.0.0/ext/libxml
/home/et/.rvm/rubies/ruby-2.4.0/bin/ruby -r ./siteconf20170829-7959-r3asv6.rb extconf.rb
/home/et/.rvm/rubies/ruby-2.4.0/bin/ruby: warning: shebang line ends with \r may cause a problem
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/et/.rvm/rubies/ruby-2.4.0/bin/$(RUBY_BASE_NAME)
        --with-xml2-config
        --without-xml2-config
        --with-xml2-dir
        --without-xml2-dir
        --with-xml2-include
        --without-xml2-include=${xml2-dir}/include
        --with-xml2-lib
        --without-xml2-lib=${xml2-dir}/lib
 extconf failure: need libxml2.

    Install the library or try one of the following options to extconf.rb:

      --with-xml2-config=/path/to/xml2-config
      --with-xml2-dir=/path/to/libxml2
      --with-xml2-lib=/path/to/libxml2/lib
      --with-xml2-include=/path/to/libxml2/include


To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/et/.rvm/gems/ruby-2.4.0/extensions/x86_64-linux/2.4.0/libxml-ruby-3.0.0/mkmf.log

extconf failed, exit code 1
sudo apt-get install libxml2-dev
gem install libxml-ruby -v '3.0.0'
Building native extensions.  This could take a while...
Successfully installed libxml-ruby-3.0.0
Parsing documentation for libxml-ruby-3.0.0
Installing ri documentation for libxml-ruby-3.0.0
Done installing documentation for libxml-ruby after 0 seconds
1 gem installed

gem install pg error

gem install pg -v '0.21.0'
Fetching: pg-0.21.0.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

    current directory: /home/et/.rvm/gems/ruby-2.4.0/gems/pg-0.21.0/ext
/home/et/.rvm/rubies/ruby-2.4.0/bin/ruby -r ./siteconf20170829-10669-33sjuh.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/et/.rvm/rubies/ruby-2.4.0/bin/$(RUBY_BASE_NAME)
        --with-pg
        --without-pg
        --enable-windows-cross
        --disable-windows-cross
        --with-pg-config
        --without-pg-config
        --with-pg_config
        --without-pg_config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/et/.rvm/gems/ruby-2.4.0/extensions/x86_64-linux/2.4.0/pg-0.21.0/mkmf.log

extconf failed, exit code 1
sudo apt-get install libpq-dev
gem install pg -v '0.21.0'
Building native extensions.  This could take a while...
Successfully installed pg-0.21.0
Parsing documentation for pg-0.21.0
Installing ri documentation for pg-0.21.0
Done installing documentation for pg after 0 seconds
1 gem installed

gem install capybara-webkit error

gem install capybara-webkit -v '1.14.0'
Building native extensions.  This could take a while...
ERROR:  Error installing capybara-webkit:
        ERROR: Failed to build gem native extension.

    current directory: /home/et/.rvm/gems/ruby-2.4.1/gems/capybara-webkit-1.14.0
/home/et/.rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20170829-14603-1wbv51o.rb extconf.rb
qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/et/.rvm/rubies/ruby-2.4.1/bin/$(RUBY_BASE_NAME)
        --with-gl-dir
        --without-gl-dir
        --with-gl-include
        --without-gl-include=${gl-dir}/include
        --with-gl-lib
        --without-gl-lib=${gl-dir}/lib
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include
        --without-zlib-include=${zlib-dir}/include
        --with-zlib-lib
        --without-zlib-lib=${zlib-dir}/lib
Command 'qmake ' failed

extconf failed, exit code 1
sudo apt-get install qt-sdk
gem install capybara-webkit -v '1.14.0'
Building native extensions.  This could take a while...
Successfully installed capybara-webkit-1.14.0
Parsing documentation for capybara-webkit-1.14.0
Installing ri documentation for capybara-webkit-1.14.0
Done installing documentation for capybara-webkit after 0 seconds
1 gem installed
sudo apt-get update
sudo apt-get install xvfb