Struggling to run ruby with openssl newbie please help

I need to have a gemfile which has openssl dependency and so I first installed openssl (I tried both ways, using sudo apt-get install openssl and also unzipping downloaded tar files). After that, I did sudo bundle config build.openssl --with-openssl-dir=/usr/local/openssl and then bundle install but it gives me a bunch of errors saying – checking for t_open() in -lnsl…no checking for socket() in -lsocket…no and a host of other similar stuff. Also something like openssl_missing.c: error : invalid application of sizeof to incomplete type ‘HMAC_CTX’ … (Sorry I cannot post the exact screenshot because its on my work PC). I tried with Openssl 1.1.1 as well as 3.0.0 but nothing works. I also tried doing rvm install pkg openssl and tried rebuilding ruby with openssl path as $HOME/.rvm/usr but it gave me errors saying I should recompile with fPIC and exited. Any help is much appreciated.