Setting Up a Development Environment on a New Ubuntu Server

Detailed steps for configuring a development environment on a new Ubuntu server, including installing oh-my-zsh, MongoDB 7.x, Node.js, and securely enabling root remote access.

UbuntuServerDevelopment Environmentoh-my-zshMongoDBNode.js
Huo Ge
4

Setting Up a Development Environment on a New Ubuntu Server

Here is my usual development environment configuration after getting a new server.

Install oh-my-zsh

  1. Install zsh and necessary tools
sudo apt update
sudo apt install zsh git curl wget -y
  1. Set zsh as the default shell
chsh -s $(which zsh)
  1. Install Oh My Zsh using curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Or use wget to install:

sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  1. Install plugins

Install the syntax-highlighting plugin

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Install the zsh-autosuggestions plugin:

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  1. Edit the ~/.zshrc configuration file to enable the plugins
vim ~/.zshrc

# Find the plugins line and add these two plugins (keeping the existing ones, like git)
plugins=(git z npm zsh-autosuggestions zsh-syntax-highlighting)
  1. Apply the configuration
source ~/.zshrc

Install MongoDB 7.x

  1. First, import the MongoDB public key
# Import the public key
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
   --dearmor
  1. Create the MongoDB source list file
# Create the source file
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | \
  sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
  1. Update the package list and install MongoDB
# Update the package list
sudo apt update

# Install MongoDB
sudo apt install mongodb-org -y
  1. Start the MongoDB service and enable it to start on boot
# Start the service
sudo systemctl start mongod

# Enable start on boot
sudo systemctl enable mongod

# Check the service status
sudo systemctl status mongod

Verify the installation

# Check the MongoDB version
mongod --version

# Connect to MongoDB
mongosh

Common management commands

# Stop the service
sudo systemctl stop mongod

# Restart the service
sudo systemctl restart mongod

# View the logs
sudo tail -f /var/log/mongodb/mongod.log

Common mongosh commands

# Switch to a specific database
use dbName

# Create a root user for the admin database
db.createUser({user:"",pwd:"",roles:[{role:"root",db:"admin"}]})

# Create an administrator user for another database
db.createUser({user:"",pwd:"",roles:[{role:"dbOwner",db:""}]})


# After creating an administrator account for the admin database, it is best to enable the security option in the MongoDB configuration
# The content of /etc/mongod.conf is as follows:


# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
#  engine:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

security:
  authorization: enabled

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

Restore a backup with mongorestore

mongorestore -uuser -ppwd dbname bakpath

Install nodejs

  1. Install nvm, repository address: https://github.com/nvm-sh/nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

# Note the environment configuration
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
  1. Use nvm to install nodejs
nvm install node

Enable root remote access

  1. First, set the root password
sudo passwd root
  1. Edit the SSH configuration file
sudo nano /etc/ssh/sshd_config
  1. Find and modify the following setting (add it if it doesn't exist):
PermitRootLogin yes
  1. Restart the SSH service:
sudo systemctl restart ssh

Security recommendations:

It is recommended to use key-based login instead of a password:

# Generate a key pair on your local machine
ssh-keygen -t ed25519 -C "[email protected]"

# Copy the public key to the server
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@your_server_ip

Add the following security configurations to sshd_config:

# Disable password authentication (if using key-based login)
PasswordAuthentication no

# Limit the maximum number of authentication attempts
MaxAuthTries 3

# Use strong encryption algorithms
Ciphers [email protected],[email protected]
Copyright © 2025 HuoTech Blog
Contact Information