Skip to content

Website & Server Help

Unlimited Webspace Help

Menu
  • Home
  • Apps
  • Website
    • Sending email from a WordPress website hosted on an IONOS server
    • How to increase Upload Max Filesize
    • How to reset a WordPress password
    • 22 Ways To Speed-Up A Plesk Website
  • Server
    • Linux or Plesk Server Error 500
    • Windows Server: File cannot be loaded. The file is not digitally signed.
    • Adding or modifying IP addresses on a Linux server
    • Installing Remote Desktop on Debian 12
    • Installing Remote Desktop on Ubuntu 22.04
    • How To Install a Let’s Encrypt SSL in Apache on Debian/Ubuntu
  • Favs
    • How to Connect to a Server
    • The Ultimate Guide to Setting Up a Proper Plesk Email Server With IONOS
    • The Ultimate IONOS Migration Guide
    • Help! My Plesk Websites Are Down!
    • Running tests for a slow server or dropped packets
    • Checking File System and Hard Drive Health
Menu

Installing MongoDB 6 with NodeJS 18 on Ubuntu 22.04

Posted on March 24, 2023October 17, 2023 by admin

Note: This guide is now deprecated.

Are you trying to install MongoDB 6 on Ubuntu 22.04 without using libssl1.1? Do you need to set up MongoDB using libssl3 on Ubuntu? Did you install Node.JS on Ubuntu to find it’s only version 12? Keep reading to follow along.

MongoDB 6.0 is now installable from MongoDB repositories on Ubuntu 22.04 without requiring libssl1.1. First, install wget and gpg:

sudo apt install wget gpg -y

Next, import and install the MongoDB public key:

wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | gpg --dearmor > packages.mongodb.gpg
sudo install -D -o root -g root -m 644 packages.mongodb.gpg /etc/apt/keyrings/packages.mongodb.gpg

Create a list file for MongoDB:

echo "deb [ arch=amd64,arm64 signed-by=/etc/apt/keyrings/packages.mongodb.gpg] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

Update your system packages:

sudo apt update

Install MongoDB:

sudo apt install -y mongodb-org

Start and enable the MongoDB service:

sudo systemctl start mongod
sudo systemctl enable mongod

Install Node 18 and NPM 9:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo bash -
sudo apt-get install -y nodejs

Test out Mongoose:

mkdir mongoose-test && cd mongoose-test
nano test.js

Add the following code in your test.js file and save:

const express = require('express');
const mongoose = require('mongoose');
const app = express();
// Connect to MongoDB
mongoose.connect('mongodb://127.0.0.1:27017/my_database', { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log('Connected to MongoDB'))
.catch(err => console.error('Error connecting to MongoDB:', err));
// Define a simple schema
const userSchema = new mongoose.Schema({
name: String,
age: Number
});
// Create a model based on the schema
const User = mongoose.model('User', userSchema);
// Define route
app.get('/', (req, res) => {
res.send('Welcome to the Mongoose app!');
});
app.listen(3000, () => {
console.log('App listening on port 3000');
});

Initialize NPM and install requires modules:

npm init -y
npm i express mongoose

Run the app:

node test.js

If you see “Connected to MongoDB” then you have successfully installed MongoDB on Debian 11!

Special Offer

The internet's fastest, cheapest, unlimited bandwidth VPS

VPS
1core | 1GB RAM | 10GB NVMe
Unlimited Bandwidth | 1Gbps
$2/month - risk free