Lesson 2: Updating your VPS

2023-03-30 498 words 3 mins read

Lesson 2: Updating your VPS
This article describes why you need to continually update your VPS and the impact it has on your security.

Why do you Update your VPS Constantly?

Keeping your VPS services and packages up to date helps prevent vulnerabilities that can be exploited by hackers when using older versions of these code bases. You should always install the latest version available of software as exploits are discovered in older versions regularly and developers have to update their codes to remove these back doors that can be exploited to damage your systems.

Updating your server is Linux is very simple and can be configured to run automatically on a daily, weekly, or monthly basis.

Should you Back-up your VPS Before Updating?

Yes!

Normally nothing goes wrong when updating and 9 times out of 10 you will usually be ok.

However, making changes to your server can always run the risk of having unexpected results when updating and upgrading to new versions and packages. Code can sometimes break or installations can get hung up. It is recommended to back up your system before every update just in case you experience adverse effects after an update.

To backup your server see here:

How do you Update your VPS?

To check if you have any updates available, you will see a message in your terminal when you SSH login to your VPS similar to this one:

Update 2

To update will depend on your Linux distribution, but for our case since we are using Ubuntu we will run the following commands:

sudo apt -y update

Once complete, run the next command:

sudo apt -y upgrade

Your system will install and upgrade all the necessary packages.

How Often Should you Update your VPS?

It’s recommended to run updates at least once a week.

How to Create Automated Updates for VPS?

To create a script and cron job that auto-updates and upgrades your Ubuntu VPS once a week, follow these steps:

  1. Create a new script file using your preferred text editor:
sudo nano /root/update-vps.sh
  1. Add the following commands to the script file:

#!/bin/bash

# Update package lists
apt update

# Upgrade installed packages
apt upgrade -y

# Clean up package cache and old dependencies
apt autoremove -y
apt autoclean -y

This script will update the package lists, upgrade any installed packages, and then clean up the package cache and old dependencies.

  1. Make the script executable:
sudo chmod +x /root/update-vps.sh
  1. Add a cron job to run the script once a week:
sudo crontab -e

This will open the cron tab configuration file in your default text editor.

  1. Add the following line to the file to run the script every Sunday at 3 am:
0 3 * * 0 /root/update-vps.sh

This cron job will run the script at 3 am every Sunday. You can customize the timing as per your requirement.

  1. Save and close the file.

That’s it! Your Ubuntu VPS will now automatically update and upgrade itself once a week using the script and cron job you created.


Tags: IT Coding

author

Authored By Is-Rael Landes

Is-Rael Landes, a good man living on the earth, loving making website, teaching others and coding.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it