rbenv: gem install bundler Gem::FilePermissionError

Tags

gem install bundler
Fetching: bundler-2.0.1.gem (100%)
ERROR: While executing gem … (Gem::FilePermissionError)
You don’t have write permissions for the /var/lib/gems/2.5.0 directory.

Solution:
Check the ruby path: which ruby
If the output is /usr/bin/ruby then that’s not correct, the output should be /home/testvm1/.rbenv/shims/ruby
To solve it:
$ echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.bashrc
$ echo ‘eval “$(rbenv init -)”‘ >> ~/.bashrc
$ exec $SHELL ## or exec -l $SHELL (restart the shell)

$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ echo ‘export PATH=”$HOME/.rbenv/plugins/ruby-build/bin:$PATH”‘ >> ~/.bashrc
$ exec $SHELL ## or exec -l $SHELL (restart the shell)

$ git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

# list all available rubies online
$ rbenv install -l

Advertisements

How to install rbenv in Ubuntu 18

Tags

$ sudo apt update
$ sudo apt install rbenv

$ echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.bashrc
$ echo ‘eval “$(rbenv init -)”‘ >> ~/.bashrc
$ exec $SHELL # or exec -l $SHELL

$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ echo ‘export PATH=”$HOME/.rbenv/plugins/ruby-build/bin:$PATH”‘ >> ~/.bashrc
$ exec $SHELL or exec -l $SHELL ## To restart your shell

$ git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

# list all available rubies online
$ rbenv install -l

$ sudo apt install nodejs

ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension.

Tags

Problem:
$ gem install nokogiri
Building native extensions. This could take a while…
/usr/lib/ruby/2.5.0/rubygems/ext/builder.rb:76: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.

current directory: /var/lib/gems/2.5.0/gems/nokogiri-1.10.2/ext/nokogiri
/usr/bin/ruby2.5 -r ./siteconf20190412-31552-1vk6gfn.rb extconf.rb
mkmf.rb can’t find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.5.0/gems/nokogiri-1.10.2 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.10.2/gem_make.out

Solution:
sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev

sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev

Reference:
https://stackoverflow.com/questions/47275097/nokogiri-gem-error-failed-to-build-gem-native-extension
https://stackoverflow.com/questions/33996523/error-installing-nokogiri-failed-to-build-gem-native-extension-libiconv-is-mi

Create symlink

Tags

ln -s original_path shortcut_link
example:

ln -s /home/armano/.rbenv/versions/jruby-9.2.1.0/lib/ruby/gems/shared/gems/logstash-core-plugin-api-2.1.28-java/ logstash-core-plugin-api


ln -s /home/armano/.rbenv/versions/jruby-9.2.1.0/lib/ruby/gems/shared/gems/logstash-core-6.7.1-java/lib logstash-core

Elastic APM Server

Tags


$ sudo -i service apm-server status
● apm-server.service - Elastic APM Server
Loaded: loaded (/lib/systemd/system/apm-server.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: https://www.elastic.co/solutions/apm


$ sudo /bin/systemctl daemon-reload
$ sudo /bin/systemctl enable apm-server.service
Synchronizing state of apm-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apm-server


$ sudo -i service apm-server start
$ sudo -i service apm-server status
● apm-server.service - Elastic APM Server
Loaded: loaded (/lib/systemd/system/apm-server.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-04-04 16:21:41 PST; 3s ago
Docs: https://www.elastic.co/solutions/apm
Main PID: 7609 (apm-server)
Tasks: 7 (limit: 4915)
CGroup: /system.slice/apm-server.service
└─7609 /usr/share/apm-server/bin/apm-server -c /etc/apm-server/apm-server.yml -path.home /usr/share/apm-server -path.conf

Apr 04 16:21:41 armano-vm systemd[1]: Started Elastic APM Server.

Logstash

Tags

https://www.elastic.co/guide/en/logstash/current/installing-logstash.html
$ sudo apt-get update && sudo apt-get install logstash

$ sudo su
$ cd /usr/share/logstash
$ ./bin/logstash -e ‘input { stdin { } } output { stdout {} }’
The stdin plugin is now waiting for input:
[INFO ] 2019-04-04 17:01:22.642 [Ruby-0-Thread-1: /usr/share/logstash/lib/bootstrap/environment.rb:6] agent – Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[INFO ] 2019-04-04 17:01:23.706 [Api Webserver] agent – Successfully started Logstash API endpoint {:port=>9600}

Reference:
https://www.elastic.co/guide/en/logstash/current/introduction.html

Elasticsearch to start automatically when the system boots up

Tags

To configure Elasticsearch to start automatically when the system boots up, run the following commands:
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service

Elasticsearch can be started and stopped as follows:

sudo systemctl start elasticsearch.service
sudo systemctl stop elasticsearch.service

Reference: https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html#deb

Installing curb Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

Tags

,


Installing curb 0.9.8 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /home/armano/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/curb-0.9.8/ext
/home/armano/.rbenv/versions/2.3.0/bin/ruby -r ./siteconf20190228-13905-5hha70.rb extconf.rb
checking for curl-config... no
checking for main() in -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/armano/.rbenv/versions/2.3.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 `': 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.

Solution:
$ sudo apt-get install libcurl3-dev

References: https://stackoverflow.com/questions/20374290/an-error-occurred-while-installing-curb-0-8-5

Bundler could not find compatible versions for gem “bundler”

Bundler could not find compatible versions for gem “bundler”:
In Gemfile:
bundler-audit (~> 0.5.0) was resolved to 0.5.0, which depends on
bundler (~> 1.2)

rails (~> 4.2.10) was resolved to 4.2.10, which depends on
bundler (= 1.3.0)

Current Bundler version:
bundler (2.0.1)
This Gemfile requires a different version of Bundler.
Perhaps you need to update Bundler by running `gem install bundler`?

Could not find gem ‘bundler (= 1.3.0)’, which is required by gem ‘rails (~> 4.2.10)’, in any of the sources.

Solution:
$ gem list
* bundler (2.0.1, 1.16.1, 1.9.0)
gem uninstall bundler
Select gem to uninstall:
1. bundler-1.9.0
2. bundler-1.16.1
3. bundler-2.0.1
4. All versions
> 3

We will use the bundler-1.16.1

BUILD FAILED recipe for target ‘ext/openssl/all’ failed

$ rbenv install 2.3.0
Downloading ruby-2.3.0.tar.bz2…
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.bz2
Installing ruby-2.3.0…

BUILD FAILED (Ubuntu 18.04 using ruby-build 20190130-4-g0e33b11)

Inspect or clean up the working tree at /tmp/ruby-build.20190226212303.24449
Results logged to /tmp/ruby-build.20190226212303.24449.log

Last 10 log lines:
M_ASN1_OCTET_STRING_print(out, ext->value);
^~
Makefile:301: recipe for target ‘ossl_x509ext.o’ failed
make[2]: *** [ossl_x509ext.o] Error 1
make[2]: Leaving directory ‘/tmp/ruby-build.20190226212303.24449/ruby-2.3.0/ext/openssl’
exts.mk:206: recipe for target ‘ext/openssl/all’ failed
make[1]: *** [ext/openssl/all] Error 2
make[1]: Leaving directory ‘/tmp/ruby-build.20190226212303.24449/ruby-2.3.0’
uncommon.mk:203: recipe for target ‘build-ext’ failed
make: *** [build-ext] Error 2

Solution:
# for ruby = 2.4
$ sudo apt install libssl-dev
$ rbenv install `version`

https://github.com/rbenv/ruby-build/issues/1199
https://github.com/rbenv/ruby-build/issues/1146