461 words
2 minutes
Notes on Setting Up a Debian Environment

The instance I’m working with was created on Google Cloud, which doesn’t enable SSH login by default. To keep server management in one place, I use Termius.

Enabling SSH Login#

  1. Open the terminal through the built-in SSH window

Built-in SSH window

  1. Set a password for the root user
Terminal window
# Switch to the root user
sudo -i
# Set the password
passwd
  1. Edit PermitRootLogin and PasswordAuthentication in the sshd_config file
Terminal window
vi /etc/ssh/sshd_config

Editing sshd_config

  1. Restart the server
  2. Log in with Termius

Logging in with Termius

Once logged in, you should see something like this

Logged in

Installing nvm#

1. Update system packages#

First, make sure your system packages are up to date:

Terminal window
sudo apt update
sudo apt upgrade -y

2. Install NVM#

You can install NVM from its GitHub repository with the following command:

Terminal window
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Note that v0.39.7 is the NVM version number — check NVM’s GitHub page for the latest release.

3. Load NVM#

After installation, load NVM into your shell session:

Terminal window
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

To load NVM automatically every time a shell starts, append the commands above to your shell config file such as ~/.bashrc, ~/.zshrc, or ~/.profile:

Terminal window
echo 'export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"' >> ~/.bashrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.bashrc

Then reload the shell config:

Terminal window
source ~/.bashrc

4. Verify the NVM installation#

Check that NVM was installed successfully:

Terminal window
nvm -v

nvm version output

5. Install Node.js#

Install the latest LTS version of Node.js with NVM:

Terminal window
nvm install --lts

You can also install a specific version, for example:

Terminal window
nvm install 14.17.0

6. Set the default Node.js version

Use the following commands to set a default version:

Terminal window
# List installed Node versions
nvm list
# Set the default version
nvm alias default 14.17.0

7. Verify Node.js and npm

Finally, confirm that Node.js and npm are installed:

Terminal window
node -v
npm -v

node and npm versions

Installing MongoDB 6#

  1. Add the repository for Ubuntu:
Terminal window
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.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
  1. Add the signing key
Terminal window
curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
--dearmor
  1. Update apt and install MongoDB
Terminal window
sudo apt update && sudo apt install mongodb-org -y
  1. Start the MongoDB service

Once installation finishes, start the service

Terminal window
sudo systemctl start mongod
  1. Enable MongoDB on boot

Make the MongoDB service start automatically with the system

Terminal window
sudo systemctl enable mongod
  1. Verify the installation

Check the service status to make sure it’s running

Terminal window
sudo systemctl status mongod

Output like the following means MongoDB is up and running

mongod status

Installing Git#

  1. Update the APT package database

First, make sure your APT package database is current

Terminal window
sudo apt update
  1. Install Git
Terminal window
sudo apt install git -y
  1. Verify the installation

Once it’s done, confirm Git works

Terminal window
git -v

Installing PM2#

With Node.js and npm in place, install PM2 globally

Terminal window
npm install -g pm2

Start your Node.js project with PM2. For example, if the entry file is main.js

Terminal window
pm2 start main.js --name "steam-shared-service"

Verify the project is running

Hit one of the service’s endpoints with Apifox

Testing the API with Apifox

Notes on Setting Up a Debian Environment
https://www.mihouo.com/en/posts/front/steamshared/setting-up-a-debian-environment-a-step-by-step-guide/
Author
Jia
Published at
2024-06-05
License
CC BY-NC-SA 4.0