'Rails deployment failed to install dependency gems - Elastic Beanstalk

I'm trying to deploy a rails app in Elastic Beanstalk but I keep encountering this error: Instance deployment failed to install dependency gems that you defined in 'Gemfile'. I'm stuck and not sure how to resolve this?

Here's the log:

2022-02-05 20:57:40    INFO    Deploying new version to instance(s).
2022-02-05 20:57:48    ERROR   Instance deployment failed to install dependency gems that you defined in 'Gemfile'. For details, see 'eb-engine.log'. The deployment failed.
2022-02-05 20:57:48    ERROR   Instance deployment failed. For details, see 'eb-engine.log'.
2022-02-05 20:57:51    ERROR   [Instance: i-0fd0e5b3638cb7ab1] Command failed on instance. Return code: 1 Output: Engine execution has encountered an error..
2022-02-05 20:57:51    INFO    Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2022-02-05 20:57:51    ERROR   Unsuccessful command execution on instance id(s) 'i-0fd0e5b3638cb7ab1'. Aborting the operation.
2022-02-05 20:57:51    ERROR   Failed to deploy application.

Update: Retrieved the logs and this is what I found

 An error occurred during execution of command [app-deploy] - [stage ruby application]. Stop running the command. Error: install dependencies in Ge
mfile failed with error Command /bin/sh -c bundle _2.3.6_ install --local failed with error exit status 7. Stderr:Don't run Bundler as root. Bundler can ask for sudo if it is needed
, and
installing your bundle as root will break this application for all non-root
users on this machine.
Could not find nokogiri-1.13.1-x86_64-linux in any of the sources



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source