My actual Linux setup with Debian 12

Last updated on September 01, 2023

I have been a Linux user for almost 7 years. I was introduced to it by my undergraduate advisor, Daniel S. Souza, who suggested it to me after I encounter some problems while compiling Fortran codes in Windows. At that time, my knowledge of it was close to nonexistent. Everything I knew about it was related to its ‘difficulty’ of use. Quotation marks is just to highlighted this misconception.

Background

The distribution I used most during this time was Elementary OS, although I initially started with Ubuntu. In fact, it was through Ubuntu that I learned about all the flexibility and ease of using the Linux operating system. The first thing that impressed me was how easy it is to install a compiler, in this case, gfortran. A simple command like

sudo apt install gfortran

was all it took to install a Fortran compiler and run code.

As I was discovering a new world, I decided to test various Linux distributions, including Linux Mint, Arch Linux, Elementary OS, and, of course, Debian. When I first installed Debian around 2017, it did not have easy support for non-free firmware as it does nowadays, particularly with Debian 12 (Bookworm). So, I preferred to stick with a ready-to-go distribution because, in the end, what really matters is the work done. After some distro hopping, I ended up with Elementary OS: it’s easy to install, aesthetically pleasing (what appealed to me most), based on Ubuntu, and not so difficult to use.

It being based on Ubuntu has the advantage of having all Ubuntu packages out-of-box, but this dependency also has a disadvantage (IMHO): take a while to be updated. Of course, for non-system-related applications, that is not a problem with Flatpak alongside with Flathub. For my use, the most important is stability: I do not want lost time fixing updates that broke the system. I prioritize updated (and stable) kernel, as well as compilers. In the end, it is what matters for me.

Debian 12 has everything: stability, updated kernel and compilers, easy installation, and support of non-free-firmware. It has only one defect: not having Pantheon desktop environment. Anyway, GNOME 43 shipped with Debian is sufficient. Below, I will share the post-installation process I have automated using a bash script.

Setting up the new system

Firstly, as I installed Debian 12 using netinst.iso, it is required add $USER to sudoers in order to use sudo. To perform this, run the following command:

su -c '
echo "
# Adding $USER to sudoers
$USER ALL=(ALL:ALL) ALL
" | tee -a /etc/sudoers > /dev/null'

In short, the previous command append the current $USER to sudoers file in the /etc/sudoers directory. Now, $USER is able to run sudo, necessary to install any package (or any command that request sudo privileges). Although the netinst.iso downloads almost all packages during the installation, it can be a good move update the system:

sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y

Now, we are ready to download all important packages to have the work done.

sudo apt install bash-completion vim wget curl htop btop git \
     build-essential gfortran cmake gdb gnome-console geary docker.io \
     gnuplot ruby-dev timeshift inkscape gimp -y

The following list presents a brief explanation of each package:

  1. bash-completion: assists in creating new completions for bash shell
  2. vim: a powerful yet lightweight terminal-based text editor
  3. wget: a command-line tool for retrieving files from the internet
  4. curl: A tool with similar functionality to wget
  5. htop: a useful terminal-based system monitoring
  6. btop: an enhanced htop
  7. git: a version control system
  8. build-essential: provides tools for compiling software
  9. gfortran: a Fortran compiler
  10. cmake: used for building automation
  11. gdb: the GNU debugger
  12. gnome-console: GNOME terminal
  13. geary: a clean and easy to use e-mail client
  14. docker.io: used for containerization
  15. gnuplot: a powerful command-line plotting software
  16. ruby-dev: provides header files for compiling Ruby (this website is an example)
  17. timeshift: used for filesystem snapshots for backup purposes
  18. inkscape: a versatile vector graphics software
  19. gimp: an image editor

As we are downloading a new terminal and e-mail client, we are going to remove gnome-terminal and evolution, shipped with GNOME

sudo apt remove gnome-terminal evolution -y
sudo apt autoremove -y

For those using a laptop with fingerprint reader, GNOME offers the option to login and substitute sudo password with fingerprint. To this, simply install the following packages:

sudo apt install fprintd libpam-fprintd -y

As I mentioned above, flatpak allows one to install updated applications that are not in the system repository while sandboxing them.

sudo apt install flatpak gnome-software-plugin-flatpak
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo

The above command install flatpak and a plugin to integrate the applications in GNOME software. Although I rarely use the software store, it can be helpful. The last command adds Flathub to flapak repositories, the biggest flapak repository.

My computing stack is based on C/C++ codes alongside Python scripts. Thus, we need some packages for it.

sudo apt install libeigen3-dev libsuitesparse-dev libopenblas-dev -y

libeigen3-dev installs the C++ headers files of the Eigen library, a template-based linear algebra library. libsuitesparse-dev provides a set of packages for sparse-matrix-related computing, developed by Tim Davis. libopenblas-dev offers an optimized implementation of the BLAS library. In summary, these packages are used for linear algebra-related computing in C++. In addition to these packages, there is also petsc-dev, which is a toolkit for parallel computing. However, I prefer compiling PETSc from source, as I have not had a good experience using the repository package

petsc_dir="$HOME/Desktop"
git clone -b release https://gitlab.com/petsc/petsc.git ${petsc_dir}/petsc
cd ${petsc_dir}/petsc
git pull
./configure --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich \
            --download-fblaslapack
make all check

First, we define the installation directory petsc_dir="$HOME/Desktop". I prefer to install libraries in the Desktop folder, but you can choose any directory, although it is recommend to install it in a directory inside your $HOME directory. The following commands clone petsc from GitLab, navigate to the created directory, update the repository with pull, and finally, configure and build the application. After finishing the installation, you need to set the variable in the PATH so that the system recognizes the library. To do this, simply add the following to your ~/.bashrc file:

export PETSC_DIR=$HOME/Desktop/petsc
export PETSC_ARCH=arch-linux-c-debug
export PATH=$PETSC_DIR/lib/petsc/bin/:$PATH

A bash script can easily perform this task for you

echo "
### >>> PETSc >>>
export PETSC_DIR=$HOME/Desktop/petsc
export PETSC_ARCH=arch-linux-c-debug
export PATH=$PETSC_DIR/lib/petsc/bin/:\$PATH
### <<< PETSc <<<
" | tee -a $HOME/.bashrc > /dev/null

Finally, source .bashrc file to use PETSc bin commands

source $HOME/.bashrc

Let’s install some python packages now. For system-wide usage, I prefer to install python packages from the repository. My current Python usage revolves around numerical packages: NumPy for linear algebra, SciPy, for algorithms related to scientific computing, SymPy for symbolic computing ,and Matplotlib for graphics plotting.

sudo apt install ipython3 python3-numpy python3-scipy python3-sympy \
                 python3-matplotlib -y

In the list, there is also ipython, which is an interactive shell application to run python code.

These packages are not the most updated ones, as Debian freezes the packages versions when releasing a new Debian version. Although pip is available in the repository, Debian do recommend to install externally-managed python packages, i.e., packages not managed by Debian maintainers, by using a virtual environment. This can be accomplished as

python_env_dir="$HOME/Desktop/python"
python3 -m venv ${python_env_dir}

Now we can install the latest python packages in this virtual environment (venv). To save your time, create a file requirements.txt write down all packages you want to have. In my requirements.txt file, I have

numpy
scipy
simpy
matplotlib
gmsh
ipython
ipykernel

Basically, it is the same packages that were installed system-wide, with the exception of gmsh, an incredible mesh generator that I use to generate finite element method (FEM) meshes. Then, run the following command

${python_env_dir}/bin/pip3.11 install -r requirements.txt

To automate this process, the following bash script perform all of this at once

python_env_dir="$HOME/Desktop/python"
python3 -m venv ${python_env_dir} 
touch requirements.txt
echo 'numpy
scipy
simpy
matplotlib
gmsh
ipython
ipykernel' >> requirements.txt
${python_env_dir}/bin/pip3.11 install -r requirements.txt
rm requirements.txt

To easily activate this venv, let’s create an alias for it: pyenv

touch $HOME/.bash_aliases
echo alias pyenv=\""source ${python_env_dir}/bin/activate"\" \
     | tee -a $HOME/.bash_aliases > /dev/null
eval "source $HOME/.bashrc"

Now, to activate (and use) this venv, simply type pyenv in any terminal.

To use all these programming-related packages that were installed, you will need a text editor. For me, Visual Studio Code is the best one. It has a lot of extensions that really help when one is coding. One can download a .deb package directly from its website and install it using

sudo apt install code_version.deb

As the goal here is to use bash script to facilitate the post-installation process, the following bash script installs VS Code and also installs the extensions that I use daily

sudo apt update
sudo apt upgrade -y
sudo apt install software-properties-common apt-transport-https gnupg -y
wget -O- https://packages.microsoft.com/keys/microsoft.asc \
         | sudo gpg --dearmor | sudo tee /usr/share/keyrings/vscode.gpg
echo deb [arch=amd64 signed-by=/usr/share/keyrings/vscode.gpg] https://packages.microsoft.com/repos/vscode stable main \
         | sudo tee /etc/apt/sources.list.d/vscode.list
sudo apt update
sudo apt install code -y
code --install-extension ms-python.python
code --install-extension ms-toolsai.jupyter
code --install-extension ms-vscode.cpptools
code --install-extension ms-vscode.cmake-tools
code --install-extension james-yu.latex-workshop
code --install-extension streetsidesoftware.code-spell-checker
code --install-extension streetsidesoftware.code-spell-checker-portuguese-brazilian

The extension names are self-explanatory, so you can easily understand their purposes. To see more extensions, visit its marketplace.

To use LaTeX, I highly recommend installing the full version of TeX Live available in the repository

sudo apt install texlive-full -y

If you have a poor internet connection, it might be better to download a full .iso file and install it locally. You can find more instructions on the TeX Live website.

For those interested in computational fluid dynamics (CFD), installing OpenFOAM is straightforward

curl https://dl.openfoam.com/add-debian-repo.sh | sudo bash -y
sudo apt-get update
sudo apt-get install openfoam-default -y
sudo apt install paraview -y

Customizations

In addition to system-related configurations, I also make a few customizations to my setup: removing the background (I prefer a plain black one), removing the grub wallpaper, and removing the grub splash image (I like to see the components being loaded while booting the system). As usual, a bash script performs all of these tasks at once:

echo 'set color_normal=light-gray/black
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray"' \
| sudo tee /boot/grub/custom.cfg > /dev/null

echo '
# Remove grub wallpaper
GRUB_BACKGROUND=""

# Remove grub splash image
GRUB_CMDLINE_LINUX_DEFAULT=""
' | sudo tee -a /etc/default/grub > /dev/null

sudo update-grub

Final configurations

After all setup up, let us take a screenshot of the system for fast and easy restore the system at this point. This is performed by timeshift

sudo timeshift --create --comments "Initial setup"

Now, the system is ready to use and secure in case you make a mistake. Although it is not mandatory to reboot the system, it is recommended so that all modifications take effect.

sudo reboot

Plain bash script

Below is a plain bash script that automates all the steps explained earlier, making it easy to set up a new machine quickly. To download the script, simply click here.

#!/bin/bash

start=`date +%s`

echo "

===============================================================================
                          DEBIAN 12 POST INSTALLATION

DIEGO MAGELA LEMOS
diegomagela@usp.br
===============================================================================

"

# Firstly, one should add the $USER to sudoers
echo "

Adding $USER to sudoers...
Enter root password

"

su -c '
echo "
# Adding $USER to sudoers
$USER ALL=(ALL:ALL) ALL
" | tee -a /etc/sudoers > /dev/null'

echo "

Completed!

"


# Update the system
echo "

Updating the system...

"
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y

echo "

Completed!

"

# Install some packages
echo "

Installing packages...

"

sudo apt install bash-completion vim wget curl btop htop git \
     build-essential gfortran cmake gdb gnome-console geary docker.io \
     gnuplot ruby-dev timeshift inkscape gimp -y
sudo apt remove gnome-terminal -y && sudo apt autoremove -y

# Enable fingerprint login (Gnome)
sudo apt install fprintd libpam-fprintd -y

echo "

Completed!

"

# Install flatpak
echo "

Installing flatpak...

"

sudo apt install flatpak gnome-software-plugin-flatpak
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo


# Customizing grub 
echo "

Customizing grub...

"

# Remove grub wallpaper
echo '
# Remove grub wallpaper
GRUB_BACKGROUND=""

# Remove grub splash image
GRUB_CMDLINE_LINUX_DEFAULT=""
' | sudo tee -a /etc/default/grub > /dev/null

# Change grub colors
echo 'set color_normal=light-gray/black
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray"' \
| sudo tee /boot/grub/custom.cfg > /dev/null

# Update grub
sudo update-grub

echo "

Completed!

"

# Remove desktop wallpaper
echo "

Removing background...

"

gsettings set org.gnome.desktop.background picture-uri ""
gsettings set org.gnome.desktop.background picture-uri-dark ""
gsettings set org.gnome.desktop.background primary-color black

echo "

Completed!

"

# Install C/C++ packages
echo "

Installing C/C++ packages...

"
sudo apt install libeigen3-dev libsuitesparse-dev libopenblas-dev -y

echo "

Completed!

"

# Install python packages
echo "

Installing Python packages...

"
sudo apt install ipython3 pipx python3-numpy python3-scipy python3-sympy \
                 python3-matplotlib -y
echo "

Completed!

"

# Create python environment
echo "

Creating Python environment...

"

python_env_dir="$HOME/Desktop/python"
python3 -m venv ${python_env_dir} 
touch requirements.txt
echo 'numpy
scipy
simpy
matplotlib
gmsh
ipython
ipykernel' >> requirements.txt
${python_env_dir}/bin/pip3.11 install -r requirements.txt
rm requirements.txt

touch $HOME/.bash_aliases
echo alias pyenv=\""source ${python_env_dir}/bin/activate"\" \
     | tee -a $HOME/.bash_aliases > /dev/null
eval "source $HOME/.bashrc"

echo "

Completed!

"

# Install VSCode
echo "

Installing Visual Studio Code...

"

sudo apt update && sudo apt upgrade -y
sudo apt install software-properties-common apt-transport-https gnupg -y
wget -O- https://packages.microsoft.com/keys/microsoft.asc \
         | sudo gpg --dearmor | sudo tee /usr/share/keyrings/vscode.gpg
echo deb [arch=amd64 signed-by=/usr/share/keyrings/vscode.gpg] https://packages.microsoft.com/repos/vscode stable main \
         | sudo tee /etc/apt/sources.list.d/vscode.list
sudo apt update
sudo apt install code -y
code --install-extension ms-python.python
code --install-extension ms-toolsai.jupyter
code --install-extension ms-vscode.cpptools
code --install-extension ms-vscode.cmake-tools
code --install-extension james-yu.latex-workshop
code --install-extension streetsidesoftware.code-spell-checker
code --install-extension streetsidesoftware.code-spell-checker-portuguese-brazilian
echo "

Completed!

"

# Install PETSc

echo "

Installing PETSc...

"

petsc_dir="$HOME/Desktop"
git clone -b release https://gitlab.com/petsc/petsc.git ${petsc_dir}/petsc
cd ${petsc_dir}/petsc
git pull
./configure --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich \
            --download-fblaslapack
make all check
cd

echo "
### >>> PETSc >>>
export PETSC_DIR=$HOME/Desktop/petsc
export PETSC_ARCH=arch-linux-c-debug
export PATH=$PETSC_DIR/lib/petsc/bin/:\$PATH
### <<< PETSc <<<
" | tee -a $HOME/.bashrc > /dev/null

eval "source $HOME/.bashrc"

echo "

Completed!

"

# Install OpenFOAM (openfoam.com) using docker

echo "

Installing OpenFOAM [openfoam.com] using docker...

"

openfoam_dir="$HOME/Desktop/OpenFOAM"

mkdir ${openfoam_dir}
cd ${openfoam_dir}
wget https://develop.openfoam.com/packaging/containers/-/raw/main/openfoam-docker
chmod +x openfoam-docker
ln -sf openfoam-docker openfoam-default

sudo docker pull opencfd/openfoam-default

echo alias openfoam=\""sudo bash ${openfoam_dir}/openfoam-default"\" \
     | tee -a $HOME/.bash_aliases > /dev/null
eval "source $HOME/.bashrc"

# Add the repository
curl https://dl.openfoam.com/add-debian-repo.sh | sudo bash -y

# Update the repository information
sudo apt-get update

# Install preferred package. Eg,
sudo apt-get install openfoam-default -y


sudo apt install paraview -y

echo "

Completed!

"

# Install Texlive
echo "

Installing Texlive...

"
# ./install_tex_live path_to_iso
sudo apt install texlive-full -y

echo "

Completed!

"

echo "

Updating the system...

"

sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y

echo "

Completed!

"


echo "

Creating a snapshot (backup) of the system...

"

sudo timeshift --create --comments "Initial setup"

echo "

Completed!

"


echo "

==========================
          FINISH
==========================

"

end=`date +%s`

echo Execution time was `expr $end - $start` seconds | tee $HOME/Documents/log.txt

echo "

Rebooting the system...

"
sleep 5
sudo reboot
#bash, #linux, #debian