Unable to install ruby from source in ubuntu 18.04 docker image - ruby

I am installing ruby 2.7.2 on a docker container that uses ubuntu:18.04.c I first tried to install rbenv but it did not offer the version I need so I resorted to installing from source. However when installing from source the make install does not pass. This is the method I used to install from source https://coderwall.com/p/3u__pq/install-ruby-from-source-on-ubuntu and this is what I looked at to resolve my issues to no avail Unable to locate package openssl-dev. Also I cannot install rvm as it is not picked up by bash.
docker file
#
# Ubuntu Dockerfile
#
# https://github.com/dockerfile/ubuntu
#
# Pull base image.
FROM ubuntu:18.04
ARG APP_NAME=<appname>
# Install.
RUN \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y build-essential openssl libssl-dev zlib1g-dev&& \
apt-get install -y software-properties-common && \
apt-get install -y byobu curl git htop man unzip vim wget openssl libffi-dev &&\
rm -rf /var/lib/apt/lists/*
RUN \
wget https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.2.tar.bz2 &&\
tar -xf ruby-2.7.2.tar.bz2
RUN cd ruby-2.7.2
RUN pwd
RUN ./ruby-2.7.2/configure --prefix=/my/ruby/dir
RUN make
RUN make install
# Set environment variables.
EXPOSE 5000
ENV HOME /root
ENV PATH="${PATH}:/my/ruby/dir"
# Define working directory.
WORKDIR /root
COPY ${APP_NAME}/ ./${APP_NAME}/
# Define default command.
CMD ["bash"]
When I did make install it is complaining that openssl is not installed however I did do apt install openssl
*** Following extensions are not compiled:
openssl:
Could not be configured. It will not be installed.
/ruby-2.7.2/ext/openssl/extconf.rb:97: OpenSSL library could not be found. You might want to use --with-openssl-dir=<dir> option to specify the prefix where OpenSSL is installed.
Check ext/openssl/mkmf.log for more details.
dbm:
Could not be configured. It will not be installed.
Check ext/dbm/mkmf.log for more details.
readline:
Could not be configured. It will not be installed.
/ruby-2.7.2/ext/readline/extconf.rb:62: Neither readline nor libedit was found
Check ext/readline/mkmf.log for more details.
gdbm:
Could not be configured. It will not be installed.
Check ext/gdbm/mkmf.log for more details.
zlib:
Could not be configured. It will not be installed.
Check ext/zlib/mkmf.log for more details.
*** Fix the problems, then remove these directories and try again if you want.
Later on this is the error message
Traceback (most recent call last):
11: from ./tool/rbinstall.rb:947:in `<main>'
10: from ./tool/rbinstall.rb:947:in `each'
9: from ./tool/rbinstall.rb:950:in `block in <main>'
8: from ./tool/rbinstall.rb:799:in `block in <main>'
7: from ./tool/rbinstall.rb:835:in `install_default_gem'
6: from ./tool/rbinstall.rb:835:in `each'
5: from ./tool/rbinstall.rb:845:in `block in install_default_gem'
4: from ./tool/rbinstall.rb:279:in `open_for_install'
3: from ./tool/rbinstall.rb:846:in `block (2 levels) in install_default_gem'
2: from /ruby-2.7.2/lib/rubygems/specification.rb:2430:in `to_ruby'
1: from /ruby-2.7.2/lib/rubygems/core_ext/kernel_require.rb:92:in `require'
/ruby-2.7.2/lib/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- openssl (LoadError)

I think your problem is here
RUN cd ruby-2.7.2
RUN pwd
RUN ./ruby-2.7.2/configure --prefix=/my/ruby/dir
You cd into ruby-2.7.2 then attempt ./ruby-2.7.2/configure ... but you are already in the directory ruby-2.7.2 so this line
RUN ./ruby-2.7.2/configure --prefix=/my/ruby/dir
should fail.
Try replacing
RUN ./ruby-2.7.2/configure --prefix=/my/ruby/dir
with
RUN ./configure --prefix=/my/ruby/dir
You could clean up your Docerfile a bit as well by removing lines like
RUN pwd

Related

Gem Permission Error When installing fluentd plugin

When running docker on Jenkins i am getting the following error:
While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/lib/ruby/gems/3.1.0 directory.
[0m[91m /usr/lib/ruby/3.1.0/rubygems/installer.rb:712:in `verify_gem_home'
/usr/lib/ruby/3.1.0/rubygems/installer.rb:902:in `pre_install_checks'
/usr/lib/ruby/3.1.0/rubygems/installer.rb:302:in `install'
/usr/lib/ruby/3.1.0/rubygems/resolver/specification.rb:104:in `install'
/usr/lib/ruby/3.1.0/rubygems/request_set.rb:194:in `block in install'
/usr/lib/ruby/3.1.0/rubygems/request_set.rb:182:in `each'
/usr/lib/ruby/3.1.0/rubygems/request_set.rb:182:in `install'
/usr/lib/ruby/3.1.0/rubygems/commands/install_command.rb:210:in `install_gem'
/usr/lib/ruby/3.1.0/rubygems/commands/install_command.rb:226:in `block in install_gems'
/usr/lib/ruby/3.1.0/rubygems/commands/install_command.rb:219:in `each'
/usr/lib/ruby/3.1.0/rubygems/commands/install_command.rb:219:in `install_gems'
/usr/lib/ruby/3.1.0/rubygems/commands/install_command.rb:167:in `execute'
/usr/lib/ruby/3.1.0/rubygems/command.rb:323:in `invoke_with_build_args'
/usr/lib/ruby/3.1.0/rubygems/command_manager.rb:185:in `process_args'
/usr/lib/ruby/3.1.0/rubygems/command_manager.rb:149:in `run'
/usr/lib/ruby/3.1.0/rubygems/gem_runner.rb:51:in `run'
/usr/bin/gem:21:in `<main>'
I've seen forums suggest that it is the alpine version 3.14 > used in fluentd image. This image uses alpine 3.16 and the docker version is 20.10.22 so it is the very latest one. This works locally with no issues and same docker version. I have also checked which user it is running as and directory permissions both which are root and have wrx on the user level.
Docker file is below:
FROM fluent/fluentd:v1.14.6-1.1
USER root
RUN apk add --no-cache \
ca-certificates
COPY cert.cer /usr/local/share/ca-certificates/
RUN update-ca-certificates
RUN apk add --update --virtual .build-deps \
build-base ruby-dev
RUN apk add --update mariadb-dev
COPY cert.cer /usr/lib/ruby/3.1.0/rubygems/ssl_certs/cert.cer
RUN gem install fluent-plugin-sql --no-document
RUN gem install mysql2
RUN gem install bigdecimal
RUN gem install elasticsearch -v 7.17.0
RUN gem install --minimal-deps fluent-plugin-elasticsearch
RUN gem source --clear-all
RUN apk del .build-deps
USER fluent
I've tried changing the directory permissions and removing sudo altogether and no luck. Changing to other docker versions has no luck either.

Unable to install bundler after installing ruby from source

I am using a Dockerfile to build a custom ruby image as follows:
FROM debian:9
RUN apt-get update \
&& apt-get install -y \
build-essential \
gcc \
openssl \
procps \
wget \
zlib1g-dev \
&& cd /tmp \
&& wget http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz \
&& tar -xvzf ruby-2.0.0-p0.tar.gz \
&& ls -al \
&& cd ruby-2.0.0-p0 \
&& ./configure \
&& make \
&& make install
USER someuser
WORKDIR /home/someuser
The build finishes OK.
As a matter of fact, from within the image:
$ ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
But when I spin up the image and try to install bundler
$ gem install bundler
ERROR: Loading command: install (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
Why is that, given I have installed openssl?
edit: It is NOT a duplicate of this because (although I am using OSX) I am compiling ruby WITHIN a debian:9 image and openssl gets installed within the image (Dockerfile)
edit: installing libssl-dev as also indicated in the potential duplicate question does not solve the issue either:
(custom-ruby)*➣ $ docker run -it --user=root pkaramol/test-ruby-new bash
root#bde5e149ced7:/home/someuser# dpkg -l | grep -i ssl
ii libssl-dev:amd64 1.1.0j-1~deb9u1 amd64 Secure Sockets Layer toolkit - development files
ii libssl-doc 1.1.0j-1~deb9u1 all Secure Sockets Layer toolkit - development documentation
ii libssl1.1:amd64 1.1.0j-1~deb9u1 amd64 Secure Sockets Layer toolkit - shared libraries
ii openssl 1.1.0j-1~deb9u1 amd64 Secure Sockets Layer toolkit - cryptographic utility
root#bde5e149ced7:/home/someuser# gem install bundler
ERROR: Loading command: install (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass

Problem with Jekyll and Nokogiri installation

Im on ubuntu 18.04.2 LTS on Windows, and I have a rudimentary question. My objective is to use github template https://github.com/github/personal-website and publish it to username.github.io
I've a problem with step 4:
Build the site and make it available on a local server
bundle exec jekyll serve
hafidz#LAMBDA05:~/personal-website$ bundle exec jekyll serve
**Could not find nokogiri-1.10.1 in any of the sources**
Run `bundle install` to install missing gems.
It's already a runaround to install bundle, jekyll and nokogori, but i thought have that done. Does it need a path setup?
hafidz#LAMBDA05:~/personal-website$ bundle -v
Bundler version 2.0.1
hafidz#LAMBDA05:~/personal-website$ jekyll -v
Traceback (most recent call last):
12: from /usr/local/bin/jekyll:23:in `<main>'
11: from /usr/local/bin/jekyll:23:in `load'
10: from /var/lib/gems/2.5.0/gems/jekyll-3.8.5/exe/jekyll:11:in `<top (required)>'
9: from /var/lib/gems/2.5.0/gems/jekyll-3.8.5/lib/jekyll/plugin_manager.rb:50:in `require_from_bundler'
8: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler.rb:107:in `setup'
7: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:20:in `setup'
6: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:108:in `block in definition_method'
5: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/definition.rb:226:in `requested_specs'
4: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/definition.rb:237:in `specs_for'
3: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/definition.rb:170:in `specs'
2: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/spec_set.rb:81:in `materialize'
1: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/spec_set.rb:81:in `map!'
/var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/spec_set.rb:87:in `block in materialize': Could not find nokogiri-1.10.1 in any of the sources (Bundler::GemNotFound)
hafidz#LAMBDA05:~/personal-website$ nokogiri -v
# Nokogiri (1.10.1)
---
warnings: []
nokogiri: 1.10.1
ruby:
version: 2.5.3
platform: x86_64-linux-gnu
description: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux-gnu]
engine: ruby
libxml:
binding: extension
source: packaged
libxml2_path: "/var/lib/gems/2.5.0/gems/nokogiri-1.10.1/ports/x86_64-pc-linux-gnu/libxml2/2.9.9"
libxslt_path: "/var/lib/gems/2.5.0/gems/nokogiri-1.10.1/ports/x86_64-pc-linux-gnu/libxslt/1.1.33"
libxml2_patches:
- 0001-Revert-Do-not-URI-escape-in-server-side-includes.patch
libxslt_patches: []
compiled: 2.9.9
loaded: 2.9.9
appreciate helps
I saw something similar using Ubuntu WSL. I'd been following the Jekyll WSL instructions and got stuck. There was a nice hint on Dave Rupert's blog (link) that recommended the following and unblocked me: apt install zlibc zlib1g-dev libxml2 libxml2-dev libxslt1.1 libxslt1-dev
Here's a dump of my bash history for the session:
24 sudo apt install ruby
26 gem update jekyll
27 code .
28 sudo apt-get update -y && sudo apt-get upgrade -y
30 sudo gem update
31 sudo apt-add-repository ppa:brightbox/ruby-ng
32 sudo apt-get update
33 sudo apt-get install ruby2.5 ruby2.5-dev build-essential dh-autoreconf
35 sudo gem update
37 sudo gem install jekyll bundler
38 jekyll -v
40 sudo bundle update
45 sudo bundle install
47 sudo apt install zlibc zlib1g-dev libxml2 libxml2-dev libxslt1.1 libxslt1-dev
48 sudo gem install nokogiri -v '1.8.2' --source 'https://rubygems.org/'
49 sudo bundle install
51 bundle exec jekyll -v
52 bundle exec jekyll serve
54 sudo bundle update
56 bundle exec jekyll serve
57 history
58 history > history.txt

Whenever gem 'failed to load command: rake'

looking for some help.
I am running a rails app (v3.2.5) with the whenever gem (v0.9.7) and rake (v11.2.2). I am also doing this in a docker container image ruby:2.3 (cron was installed and bundle install was ran)
Here is my schedule.rb
set :environment, ENV['RAILS_ENV']
every '*/2 9,10,11,12,13,14,15,16 * * 1-5' do
rake "import_csv", output: {:error => 'log/import_csv_errors.log', :standard => 'log/import_csv.log'}'
end
note RAILS_ENV is set at container launch to development
Here is my cron job that is on the container after build (crontab -l):
# Begin Whenever generated tasks for: /usr/src/app/config/schedule.rb
*/2 9,10,11,12,13,14,15,16 * * 1-5 /bin/bash -l -c 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log'
# End Whenever generated tasks for: /usr/src/app/config/schedule.rb
When this cron job runs, the logs return:
import_csv_errors.log
Bundler::GemNotFound: Could not find rake-11.2.2 in any of the sources
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:95:in `block in materialize'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `map!'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `materialize'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:140:in `specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:185:in `specs_for'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:174:in `requested_specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/environment.rb:19:in `requested_specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:14:in `setup'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:95:in `setup'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/setup.rb:19:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
import_csv.log
bundler: failed to load command: rake (/usr/local/bin/rake)
Now here is the odd thing. If I copy the cron job command:
/bin/bash -l -c 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log'
and run this in the container, it works fine, but if the cron job runs it, I get thos errors in the logs!!! I am at a lost here...
I've tried adding
env :PATH, ENV['PATH']
env :GEM_PATH, '/usr/local/bundle'
to the top of schedule.rb and I tried doing
command 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log'
Instead of using rake in the task and I get the same errors..
Any help is appriciated
I've fixed the same error by modifying the Dockerfile with:
RUN gem update --system 2.6.12
RUN gem install bundler --version 1.14.6
And schedule.rb:
ENV.each { |k, v| env(k, v) }
I have updated my rake version and it worked for me. Below are the steps I followed:
sudo bundle update rake
sudo bundle install
Open a Rakefile and replace the line rake/rdoctask with require 'rdoc/task'.
I resolved my issue by using a different image and building as I needed it instead of using docker hub image ruby:2.x.
Dockerfile (edited to fit thread):
FROM ubuntu:14.04
# Installs needed to run rails on ubuntu 14.04 (must use mysql 5.6 or 5.5):
RUN apt-get update && apt-get install -y apache2 curl git build-essential libmysqlclient-dev mysql-server-5.6 nodejs make
RUN apt-get update && apt-get install -y ruby-dev zlib1g-dev
RUN gem install rails --version 3.2.5 --no-ri --no-rdoc
# Update ruby to v2.2 (optional)
RUN apt-get install -y software-properties-common && apt-add-repository ppa:brightbox/ruby-ng
RUN apt-get update && apt-get install -y ruby2.2
# Install cron
RUN apt-get install -y cron
# Finish the build
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# If you code is in the same directory you ran docker build then:
COPY . /usr/src/app
RUN bundle install
RUN whenever --update-crontab
CMD ["passenger start"]

How to install ruby-oci8, the ruby client for oracle on debian based systems (also ubuntu)

Most information found even on the client's homepage is somehow inaccurate or outdated.
This is the straight-foward method that worked for me, and I'd like to share with you.
It would be nice if this answer can be expanded by some other system specific methods that might be harder to get it installed on.
Oracle ruby-oci8
Installing in Ubuntu LTS 12.04 32bit
Updated to 64bit version. Thx OneHoopyFrood
First, internal requirements
sudo apt-get install build-essential
sudo apt-get install libaio-dev
Download oracle instant client from
http://www.oracle.com/technetwork/topics/linuxsoft-082809.html
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
You’ll need both zip files, instantclient-basic AND instantclient-sdk
on your machine, make yourself root (sudo su) and make the destination folders:
mkdir /opt
mkdir /opt/oracle
cd /opt/oracle
put both files inside /opt/oracle and unzip them.
unzip instantclient-basic*
unzip instantclient-sdk*
make a symlink of instantclient for easier finding by the system
cd /opt/oracle/instantclient10_1
ln -s libclntsh.so.10.1 libclntsh.so
Now, export the LD_LIBRARY_PATH pointing to instantclient path.
export LD_LIBRARY_PATH=/opt/instantclient
NOW… you can install ruby-oci8
a. if using RVM, use:
gem install ruby-oci8
b.- if installing to system, use:
sudo gem install ruby-oci8
Hope it helps.
These are the steps to install ruby-oci8 Gem Installation in Ubuntu.
Step 1:
Download the basic & sdk instantclient zip files from https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
instantclient-basic-linux.x64-21.8.0.0.0dbru.zip
instantclient-sdk-linux.x64-21.8.0.0.0dbru.zip
Step 2:
Install following packages
sudo apt-get install build-essential
sudo apt-get install libaio-dev
Step 3:
Create a folder oracle inside /opt/
mkdir /opt/oracle
Step 4:
Go to inside /opt/oracle/
cd /opt/oracle
Step 5:
Place the basic instantclient folder inside /opt/oracle
sudo cp ~/Downloads/instantclient-basic-linux.x64-21.8.0.0.0dbru.zip /opt/oracle/
Step 6:
Place the sdk instantclient folder inside /opt/oracle
sudo cp ~/Downloads/instantclient-sdk-linux.x64-21.8.0.0.0dbru.zip /opt/oracle/
Step 7:
Unzip the basic instantclient folder
sudo unzip instantclient-basic-linux.x64-21.8.0.0.0dbru.zip
Step 8:
Unzip the sdk instantclient folder
sudo unzip instantclient-sdk-linux.x64-21.8.0.0.0dbru.zip
Step 9:
Check the folders inside /opt/oracle/. It should now have a folder named as instantclient_21_8
Step 10:
Update the runtime link path
sudo sh -c "echo /opt/oracle/instantclient_21_8 > \
> /etc/ld.so.conf.d/oracle-instantclient.conf"
Step 11:
Check the runtime link path, It should now return /opt/oracle/instantclient_21_8
cat /etc/ld.so.conf.d/oracle-instantclient.conf
Step 12:
Set the path in env
export LD_LIBRARY_PATH=/opt/oracle/instantclient_21_8:$LD_LIBRARY_PATH
Step 13:
Check the path if set properly in env. It should now have proper value set as LD_LIBRARY_PATH=/opt/oracle/instantclient_21_8:/opt/instantclient
env | grep LD_LIBRARY_PATH
Step 14:
Now try by installing the gem ruby-oci8
gem install ruby-oci8
It should work now.

Resources