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!