Tristen.
Turning My Spare Hardware into an Optimized Linux Development Machine

Turning My Spare Hardware into an Optimized Linux Development Machine

September 9, 2024 (1w ago)

After upgrading my primary PC for VR gaming and video editing, I found myself with enough spare hardware to build a secondary PC. Instead of letting it gather dust, I decided to turn it into a dedicated Linux machine for software development. Previously, I had been doing all my coding in a VirtualBox Linux VM on my primary PC and laptop, but it always felt a little constrained. Having a dedicated Linux environment seemed like the perfect solution to enhance my workflow.

If you're curious, the secondary PC build includes an Aorus Z370 motherboard, Intel i5-8600K CPU, Radeon RX 550, 2TB SSD, and 32GB of RAM—enough power to handle my development needs.

Now, let’s walk through setting up this Linux machine from scratch, starting from installing Linux, configuring the system, and optimizing it for full-stack development.


1. Installing Linux: Getting Started

Create a Bootable Linux USB Drive

To install Linux on a new machine, you’ll first need to create a bootable USB drive. I used Ubuntu, but you can choose any Linux distribution that suits you.

  • Download an ISO: Head to ubuntu.com to download the latest Ubuntu desktop ISO.

  • Create a Bootable Drive: Use a tool like Rufus (Windows) or dd (Mac/Linux) to create a bootable USB drive.

    # Mac/Linux Example:
    sudo dd bs=4M if=ubuntu.iso of=/dev/sdX status=progress oflag=sync

Installing Ubuntu

Once you have your bootable drive ready:

  • Plug in the USB drive and boot from it.
  • Follow the on-screen prompts to install Linux on your dedicated SSD.
  • Use a Wired Keyboard and Mouse: I found that during setup, it was easiest to use a wired keyboard and mouse to avoid issues with wireless devices.
  • Partitioning: If it’s a dedicated dev machine, I suggest setting up a basic partition with plenty of swap space (16-32GB depending on your RAM).
  • Install any necessary drivers, especially for your GPU if you're using a discrete graphics card like my Radeon RX 550.

2. Initial Setup: Essential Development Tools

Once your Linux installation is complete, it’s time to set up the machine for development. Here’s where we begin to optimize the system for coding.

Update and Upgrade System

First, ensure everything is up-to-date:

sudo apt update && sudo apt upgrade -y

This step ensures that you’re starting with the latest versions of system libraries and security patches.

Install Basic Developer Tools

Before installing specific development tools, you'll need some foundational packages:

sudo apt install -y git curl build-essential wget
  • Git: Essential for version control. It allows you to manage your codebase, collaborate with others, and track changes.
  • Curl: Useful for transferring data from or to a server, making it a must-have for web development and interacting with APIs.
  • Build-essential: Provides necessary tools like gcc and make, required for compiling software and building packages.

3. Optimizing Your Shell with Zsh and Powerlevel10k

By default, Ubuntu uses Bash as its shell. However, Zsh offers more powerful features like autocompletion, syntax highlighting, and better customization. To install Zsh:

sudo apt install zsh
chsh -s $(which zsh)

Next, we’ll use Oh My Zsh, a framework for managing your Zsh configuration.

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Powerlevel10k Theme for Enhanced Prompt

To give your terminal a sleek look and provide useful information (like Git status, Python environments, etc.), install the Powerlevel10k theme:

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k

Edit your .zshrc to set Powerlevel10k as the theme:

ZSH_THEME="powerlevel10k/powerlevel10k"

Afterward, reload Zsh and follow the on-screen configuration wizard to set up your custom prompt:

source ~/.zshrc

Zsh Plugins for Productivity

We’ll also install useful Zsh plugins like git, fzf, zsh-syntax-highlighting, and zsh-autosuggestions. Add these to the plugin section in your .zshrc:

plugins=(git fzf zsh-syntax-highlighting zsh-autosuggestions)

Install the necessary plugins:

# Zsh Syntax Highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

# Zsh Autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

Now reload Zsh:

source ~/.zshrc

4. Custom Aliases for Efficiency

One of the most powerful ways to optimize your development workflow is by creating custom aliases. These aliases will save you from typing long or repetitive commands.

First, create a custom file for your aliases:

nano ~/.oh-my-zsh/custom/aliases.zsh

Add the following aliases:

# System Aliases
alias ll='ls -alh'  # Long list format, show hidden files, and human-readable file sizes
alias ..='cd ..'    # Go up one directory
alias ...='cd ../..'  # Go up two directories
alias reload='source ~/.zshrc'

# Git Aliases
alias gst='git status'  # Display Git status
alias gco='git checkout'
alias gcm='git commit -m'
alias gp='git push'

# Docker Aliases
alias dps='docker ps'  # List running containers
alias dbuild='docker build .'  # Build Docker image
alias dclean='docker system prune -af'  # Clean unused containers and images

Save the file, then source it by adding the following to your .zshrc:

source $ZSH_CUSTOM/aliases.zsh

Reload Zsh:

source ~/.zshrc

5. Managing Python Versions with Pyenv

For Python development, it’s essential to manage different Python versions efficiently. pyenv is the perfect tool for this.

First, install the necessary build dependencies:

sudo apt install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev \
liblzma-dev python-openssl git

Next, install pyenv:

curl https://pyenv.run | bash

Configure your shell by adding the following to your .zshrc:

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"

Reload Zsh:

source ~/.zshrc

Now you can easily install and switch between Python versions. For example, to install Python 3.11.10:

pyenv install 3.11.10
pyenv global 3.11.10

6. Installing Docker for Containerized Development

Docker allows you to run applications in isolated containers, making it an essential tool for full-stack development. It ensures consistency across development and production environments.

Install Docker and Docker Compose:

sudo apt install docker.io docker-compose -y
sudo usermod -aG docker $USER

After logging out and back in, you can use Docker to manage your containers.


7. PostgreSQL and pgAdmin for Database Management

For back-end development, I use PostgreSQL as the database system and pgAdmin4 for managing databases.

Install PostgreSQL:

sudo apt install postgresql postgresql-contrib

To install pgAdmin:

curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo tee /etc/apt/trusted.gpg.d/pgadmin.asc
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
sudo apt install pgadmin4-desktop

8. Installing Postman for API Testing

Postman is an essential tool for testing APIs. It allows you to make requests to your backend and view responses easily.

To install Postman:

sudo snap install postman

9. Installing Node.js and Managing Versions with NVM

For JavaScript and Node.js

development, nvm (Node Version Manager) is a must. It lets you easily switch between Node.js versions.

To install nvm:

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

Add the following to your .zshrc to load nvm automatically:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Reload Zsh:

source ~/.zshrc

Now you can install Node.js:

nvm install --lts
nvm use --lts

Node.js Tools

Install some globally useful tools:

npm install -g yarn eslint prettier
  • Yarn: A faster, more deterministic alternative to npm for managing JavaScript dependencies.
  • ESLint: A tool to ensure your code follows coding standards.
  • Prettier: A code formatter that ensures consistent code style.

10. Install Bat for Enhanced File Viewing

Bat is a modern alternative to the cat command, providing syntax highlighting and other features when viewing files.

To install bat:

sudo apt install bat

To use bat instead of cat, you can alias it:

alias cat='bat'

11. Install Htop for Monitoring System Resources

Htop is an interactive system monitor that provides an easy-to-read, real-time view of system resource usage.

To install htop:

sudo apt install htop

Run it with:

htop

12. Conclusion

Setting up this dedicated Linux machine has been a game-changer for my development workflow. No longer constrained by virtual machines, I’ve now got a powerful, streamlined setup optimized for both front-end and back-end development. Whether it’s managing Python environments, working in Docker containers, or leveraging powerful shell customizations with Zsh, every tool plays a crucial role.