Come hang with us on Discord and chat directly with the team!Discordtop-bar-close-icon

2025-04-15

Step by Step Guide to Setting Up Hastebin on Your Ubuntu Server

tutorials
img

Looking to share code snippets or text quickly and securely? Hastebin is a fantastic open-source tool that lets you host your own pastebin service. It’s lightweight, user-friendly, and perfect for developers or anyone needing to share text fast. In this guide, we’ll walk you through installing Hastebin on the latest Ubuntu Server, tailored for Cloudblast users who want a seamless setup. Let’s dive in!

What You’ll Need Before Starting

Before we get going, make sure you have:

  • An Ubuntu Server (preferably the latest version) up and running.
  • Root or sudo access to execute commands.
  • A stable internet connection for downloading packages.
  • Basic familiarity with the terminal (don’t worry, we’ll keep it simple!).

Got everything? Awesome, let’s set up Hastebin!

Step 1: Update Your Ubuntu Server

First things first, let’s ensure your server is fresh and ready. Open your terminal and connect to your server via SSH. Then, run these commands to update the system:

sudo apt update
sudo apt upgrade -y

This grabs the latest package lists and installs any available updates, keeping your server secure and stable.

Step 2: Install Node.js and npm

Hastebin runs on Node.js, so we need to install it along with npm (Node’s package manager). Ubuntu’s repositories make this super easy. Type the following:

sudo apt install nodejs npm -y

Once done, verify the installation to confirm everything’s in place:

node --version
npm --version

You should see version numbers pop up. If you do, you’re good to go!

Step 3: Download and Install Hastebin

Now, let’s grab Hastebin. We’ll use npm to install it globally, which simplifies things. Run this command:

sudo npm install -g haste-server

This pulls down Hastebin and its dependencies. It might take a minute, so grab a coffee if you’d like!

Step 4: Set Up the Hastebin Directory

Hastebin needs a place to live on your server. Let’s create a directory for it and move in:

sudo mkdir /opt/hastebin
cd /opt/hastebin

Here, we’ll configure Hastebin to run smoothly.

Step 5: Configure Hastebin

Hastebin uses a configuration file to customize settings like the port it runs on. Let’s create one. Use a text editor like nano:

sudo nano config.json

Paste the following basic setup into the file:

{
    "host": "0.0.0.0",
    "port": 80,
    "keyLength": 10,
    "maxLength": 400000,
    "staticMaxAge": 86400
}

Here’s what these settings do:

  • host: Binds Hastebin to all network interfaces.
  • port: Sets Hastebin to run on port 80 (standard HTTP). You can change this if needed.
  • keyLength: Defines the length of paste IDs.
  • maxLength: Limits paste size (400,000 characters is plenty!).
  • staticMaxAge: Sets caching for static files (in seconds).

Save the file by pressing Ctrl+O, then Enter, and exit with Ctrl+X.

Step 6: Start Hastebin

Time to fire it up! From the /opt/hastebin directory, start Hastebin with:

sudo hastebin

If all’s well, Hastebin will start running. Open a web browser and navigate to your server’s IP address (e.g., http://your-server-ip). You should see Hastebin’s clean interface, ready for you to paste and share.

Step 7: Make Hastebin Run Automatically

Manually starting Hastebin every time isn’t ideal. Let’s use PM2, a handy process manager, to keep it running in the background and restart it on server reboots.

Install PM2 globally:

sudo npm install -g pm2

Now, start Hastebin with PM2:

pm2 start /usr/bin/hastebin --name hastebin

Save the PM2 configuration to ensure it runs on boot:

pm2 save
pm2 startup

Follow any on-screen instructions to complete the setup. Now, Hastebin will stay online without you lifting a finger!

Step 8: Secure Your Setup (Optional but Recommended)

Running Hastebin on port 80 is great for testing, but for production, consider these steps:

  • Add a Reverse Proxy: Use Nginx or Apache to handle traffic and enable HTTPS with a free SSL certificate from Let’s Encrypt.
  • Firewall: Restrict access with UFW. Allow only necessary ports (e.g., 80, 443, and 22 for SSH):
  • sudo ufw allow 80
    sudo ufw allow 443
    sudo ufw allow 22
    sudo ufw enable
    
  • Change the Port: If you don’t want to use port 80, update config.json and adjust your firewall rules.

These steps keep your server safe and your Hastebin instance secure.

Wrapping Up

Congrats! You’ve just set up Hastebin on your Ubuntu Server with Cloudblast. Now you can share code, notes, or any text with ease. Whether you’re collaborating with a team or just need a quick way to store snippets, Hastebin’s got you covered.

Want to take it further? Explore Hastebin’s GitHub repo for advanced tweaks or reach out to the Cloudblast community for tips on optimizing your server. Happy pasting!

Need more server tutorials? Check out our other Cloudblast guides for hosting solutions, analytics, and more!