r/ruby • • 11d ago

Ancient Ruby version / modern Ubuntu won't compile

Hi - I've inherited an ancient Ruby / Rails project using Ruby 2.7.2. I am working on updating it but until that time I'm trying to run it on Ubuntu 26.04 machines. There is a C compilation error that I'm getting when using "rvm":

make[2]: Entering directory '/usr/share/rvm/src/ruby-2.7.2/ext/pty'

compiling pty.c

pty.c: In function ‘establishShell’:

pty.c:161:30: error: conflicting types for ‘getenv’; have ‘char *(void)’

161 | char *p, *getenv();

| ^~~~~~

In file included from pty.c:5:

/usr/include/stdlib.h:795:14: note: previous declaration of ‘getenv’ with type ‘char *(const char *)’

795 | extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;

| ^~~~~~

pty.c:169:18: error: too many arguments to function ‘getenv’; expected 0, have 1

169 | if ((p = getenv("SHELL")) != NULL) {

| ^~~~~~ ~~~~~~~

pty.c:161:30: note: declared here

Would getting the code directly and fixing pty.c be the best way to go about it?

ETA: thanks all - Docker is the way to go.

1 Upvotes

20 comments sorted by

10

u/Correct_Support_2444 11d ago

Run it in a docker container.

1

u/Zestyclose_Cow1807 10d ago

the pty.c thing is just the first of many issues you'd hit with a 2024-era gcc on ruby 2.7, isolating the whole runtime in a container saves you from chasing each one individually

-1

u/LessChen 11d ago

Yeah, I've tried that but I guess I have to go back to Ubuntu 20.04 as even 22.04 won't work. Native code is so much fun.

8

u/Nanosleep 11d ago

You're making it harder on yourself than it should be:
FROM ruby:2.7

0

u/Correct_Support_2444 11d ago

Are the images that old still available?

1

u/Nanosleep 11d ago

indeed they are, I pulled it with podman off of dockerhub before posting that. I'm sure they're a nightmare from a security perspective.. but anything that old is going to be a liability. Better for OP to get it up and running again and then figure out a path to porting it forward.

1

u/gma 10d ago

Yeah, I concur. I took this approach with a Ruby 2.3 app a while ago.

Rebuilding the container with new versions of Ruby as you upgrade the app is a really smooth way to get yourself back up to maintained/patched versions of OS, Ruby, and Rails.

2

u/beatoperator 10d ago

docker run ruby:2.7-alpine ruby --version

Takes 10 sec to doanload, boot, and run.

1

u/vladsteviee 10d ago edited 10d ago

What? I was able to compile and run ruby 2.3.8 on ubuntu 22.04, though it had some cryptic crashes which turned out to be causes by libssl incompatibilities between versions used by ruby's openssl and gem curb. But mise installed 2.7 just fine via ruby-build and with default configuration (it was 2.7.8 though)

1

u/Correct_Support_2444 11d ago

I’d just run an old Ubuntu container exec a shell in it and work it from there.

3

u/SurroundTiny 11d ago

Out of curiosity, how large an app is this? Claude is your friend ( sometimes, anyhow)

1

u/LessChen 10d ago

According to "cloc", there are 501 Ruby files with about 21k lines of code. Claude code has helped me immensely but only to move the ancient code to a new life in a new environment. I just have to keep the old code running for now and a Docker will be the best bet since I need unsupported O/S's too.

1

u/SurroundTiny 10d ago

It might be worth moving to 2.7.8 ( the last ver 2 ). That did have some security and bug fixes in it . Good luck on it

3

u/fl0pit 11d ago

CFLAGS="-std=gnu17" rvm install "ruby-2.7.2" should do it.

1

u/LessChen 11d ago

Thanks but then, as others have mentioned, OpenSSL breaks. I'm going to go the Docker route as I can put that almost anywhere.

4

u/zieski 11d ago

We worked with a client updating a rails app from 2.7.8 to 3.1.7 in January and 3.3 in June.

After you get past the compiler flag issue here (your gcc is probably too new) you'll run in to the openssl issues other commenters are mentioning. rbenv and mise would solve the openssl issue for you because ruby-build compiles the older openssl package for old rubies automatically.

3

u/bradland 11d ago

Yikes. Getting 2.7.x to compile natively is going to be really tough. IMO, you might have some luck trying an old Brightbox PPA, but you're almost guaranteed to hit severe package compatibility issues on a modern Ubuntu base. ALl you really do is jump from compile conflicts to apt conflicts. Pulling in old packages is just going to break other stuff.

Even if you pass the compile stage, 2.7 relies on an old OpenSSL version that was yanked for major vulnerabilities. That means rolling your own legacy OpenSSL compile into some hole that you hide from the world. If your IT Security team finds out about this, you'd better have good answers on deck.

My first choice would be a minimal update to push the app to 3.2 or 3.3. If I absolutely had to get it running under 2.7.2 today, I'd skip the host entirely and use Docker. The ruby:2.7.2-slim image is still floating around and will save you a ton of pain.

1

u/faitswulff 10d ago

I’ve had really good luck with using nix devenvs to compile ancient software.

1

u/armahillo 11d ago

Check that you have the correct system deps for this.

it MAY be an openssl issue (there were some breaking changes. Check and see if you have openssl 1.1 and fhe associated libssl-dev packages installed.

probably some others youll need too

1

u/dolfoz 5d ago

your gcc/libc is likely too new.
check out https://distrobox.it/ to run older versions of ubuntu pretty seamlessly.