So I recently set up a Jenkins server on AWS from scratch. I configured the EC2 instance, installed all the dependencies and set up the CI pipeline. I’m documenting everything here for my future self and anyone else going down this road.
Step 1: Spin Up Your EC2 Instance
Head over to the AWS console and launch a new EC2 instance. For this setup, I went with:
- Instance type: T2.Medium (Jenkins is eats a bit of a memory, so don’t go smaller)
- AMI: CentOS 7
Once it’s up, make sure you adjust the security group to open the right ports. At minimum, you’ll need port 8080 open for Jenkins, along with SSH (port 22) for your own access.
Step 2: Install Java (OpenJDK 8)
Jenkins runs on Java, so that’s the first thing to get on the box:
sudo yum install java-1.8.0-openjdk-devel
Step 3: Install Jenkins
First, import the Jenkins repository and GPG key:
curl --silent --location http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo | sudo tee /etc/yum.repos.d/jenkins.repo
Then add the RPM key:
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
Possible Error: If you hit a GPG key error like
Public key for jenkins-2.xxx.noarch.rpm is not installed, this is the step that fixes it. Make sure you import the key before running the install.
Now install Jenkins:
sudo yum install jenkins
Start the service and enable it to auto-start on boot:
sudo systemctl start jenkins
sudo systemctl enable jenkins
Verify everything’s running:
systemctl status jenkins
Step 4: Initial Jenkins Setup
Open a browser and navigate to:
http://your_server_ip:8080
Follow the setup wizard. Jenkins will ask you to paste an initial admin password from the server (it tells you the file path on screen). From there you can install the suggested plugins and create your admin user.
A good reference for the full setup flow is the Linuxize CentOS 7 Jenkins guide.
Step 5: Install Useful Jenkins Plugins
Once you’re in the Jenkins dashboard, go ahead and install these:
- Rebuild — lets you re-trigger a build with the same parameters without re-entering everything
- Role-based Authorization Strategy — gives you fine-grained access control over who can do what in Jenkins (plugin page)
Step 6: Install Ruby on Rails, Node, and Other Dependencies
Now we need to set up the actual build environment on the Jenkins server. SSH onto Jenkins machine and install the dependencies.
System packages
yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel \
libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake \
libtool bison curl sqlite-devel
Node.js
You can install Node via the NodeSource repo:
curl -sL https://rpm.nodesource.com/setup_12.x | bash
yum install -y nodejs
Or use NVM if you want more flexibility with Node versions down the line. I my opinion, both approaches are fine.
Yarn
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo -o /etc/yum.repos.d/yarn.repo
yum install -y yarn
Ruby (via RVM)
RVM is what I use for managing Ruby versions on a server. First, import the public GPG keys:
gpg --keyserver hkp://keys.gnupg.net --recv-keys \
409B6B1796C275462A1703113804BB82D39DC0E3 \
7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Then install RVM:
curl -sSL https://get.rvm.io | bash -s stable
Load the RVM environment into your current session:
source /etc/profile.d/rvm.sh
Now install and set your Ruby version:
rvm install 2.x.x
rvm use 2.x.x --default
For more detail, this itzgeek guide is solid.
Bundler and Rails
gem install bundler
gem install rails
Once that is done, install the Ruby gems and Yarn dependencies both in your root project folder and your frontend folder.
Step 7: Set Up AWS CLI
If your project deploys to or pulls from AWS resources (S3, CodeDeploy, etc), you will need AWS CLI available on the Jenkins server:
sudo yum install python
sudo yum install awscli
Then configure credentials specifically for the Jenkins user:
sudo su -s /bin/bash jenkins
aws configure
You will be prompted for an AWS Access Key ID, Secret Access Key, region and output format. Enter those from your AWS IAM user.
Note: If you’re seeing an
Unable to locate credentialserror when Jenkins runs jobs, the fix is usually thataws configurewas run as root or your own user instead of thejenkinsuser. Make sure you switch to the jenkins user first as shown above. This ServerFault thread covers the issue in more detail.
Step 8: Install Redis
sudo yum install epel-release
sudo yum install redis -y
sudo systemctl enable redis
sudo systemctl status redis.service
DigitalOcean has a great guide on Redis + CentOS 7 if you want to go further with securing it.
Step 9: Sort Out SSH Keys for Jenkins
To let Jenkins pull from private Git repos, you need to set up SSH access:
sudo su -s /bin/bash jenkins
Then drop your private key into the ~/.ssh/ folder and set the right permissions. In the Jenkins UI, add the corresponding credentials (under Manage Jenkins → Credentials) so your pipelines can authenticate.
If builds are failing with key-related errors, double-check that the key is added both on the server and in the Jenkins credentials store.
Step 10: wkhtmltopdf Issues (if applicable)
If your app generates PDFs and you’re hitting errors with wkhtmltopdf on CentOS 7, this guide walks through the install cleanly.
Bonus: Adding Swap Memory
T2.Medium has 4GB of RAM, which is workable but can get tight when Jenkins is running multiple builds or bundling large apps. If you start seeing out-of-memory errors, adding swap is a quick fix:
First, check what you’re working with:
df -h
free -m
Then create and enable swap:
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024k
sudo mkswap /swapfile
sudo chmod 0600 /swapfile
sudo swapon /swapfile
sudo chown root:root /swapfile
To make it persist across reboots, add this line to /etc/fstab:
/swapfile swap swap defaults 0 0
Extra: Google Auth for Jenkins Login
If you want to Authenticate Jenkins behind Google login (handy for team setups), you can configure it with Google Apps. This StackOverflow thread has a decent walkthrough.
Conclusion:
That is the full setup from a fresh EC2 instance to a working Jenkins CI server with a Rails + Node build environment. The biggest issue for me were the GPG key issue during Jenkins install, getting the AWS CLI credentials to work correctly for the jenkins user and debugging memory issues during heavy builds. Hopefully this saves you some of that back-and-forth.
If anything’s unclear or you hit a step that doesn’t work quite as described, feel free to drop a comment.
