Showing posts with label Sysadmin. Show all posts
Showing posts with label Sysadmin. Show all posts

Wednesday, June 3, 2026

How Exports and Evironment Variables in Linux work

Environment variables play a crucial role in how Linux operates. Learn how to use them effectively.
Photo by Abolfazl Pahlavan on Unsplash

Environment variables play a crucial role in how Linux operates, influencing shell behavior, scripts, and applications.

Understanding these concepts can significantly enhance your usage and efficiency in a Linux environment. Let's see how.

What are Environment Variables?

Environment variables (env vars) are dynamic values that affect the processes running on a computer. They provide essential information to both the system and applications about the environment in which they are executing.

Common env vars

Frequent environment variables are listed below. These variables can be used by applications and scripts to behave differently based on the environment settings.

$PATH

This specifies the directories where executable programs are located. The system searches these directories to find commands.

$HOME

Represents the current user's home directory.

$SHELL

Represents the current user's shell.

Examples

# Print the current user's home directory
$ echo $HOME

# Print the name of the currently logged-in user
$ echo $USER

# Print the path to the current shell program
$ echo $SHELL

Setting variables

You can also set environment variables in the shell using the export command. Here's how it works.

To set a variable, simply type:

$ VARIABLE_NAME=value

For example, to set a variable named `MY_VAR`:

$ MY_VAR=123

However, this variable will only be available in the current shell session.

Exporting variables

To make a variable available to child processes, use the `export` command:

$ export VARIABLE_NAME

If we want `MY_VAR` to be available to all child processes, we would do:

$ export MY_VAR

Combining Setting and Exporting

You can also combine both actions: 

$ export MY_VAR=123

Viewing Environment Variables

To see all currently set environment variables, you can use the `env` command or simply type:

$ printenv

To display a single variable, use:

$ echo $VARIABLE_NAME

For example, the command below will show you the directories set in the `PATH` variable:

$ echo $PATH

Unsetting Environment Variables

If you need to remove an environment variable, the `unset` command can be used:

$ unset VARIABLE_NAME

For example, to unset `MY_VAR`:

$ unset MY_VAR

Practical Uses of Environment Variables

Environment variables are handy in various scenarios, let's discuss some of them.

Configuration

Many applications use environment variables for configuration settings. For instance, databases often utilize `DB_HOST`, `DB_USER`, and `DB_PASS` to connect.

Scripts

Writing scripts that depend on which user ran them can use the `USER` variable to customize behavior accordingly.

Software development, DevOps & CI/CD pipelines

When developing software, environment variables often store API keys, secrets, or other sensitive information to keep them outside the source code.

Conclusion

Understanding exports and environment variables in Linux is vital for maximizing system performance and efficiency.

Environment vars allow users to customize their working environment, improve automation in scripts, and ensure that applications can access the configuration settings they need to run correctly.

Mastering these concepts can help streamline your Linux experience and unlock new levels of productivity.

Wednesday, May 6, 2026

Getting started with .bashrc

You learned about the terminal, now you want to make it your way. Learn how... 
Photo by Giulia May on Unsplash

The .bashrc file is a vital component for those who use the Bash shell, as it allows you to customize your command-line environment.

Whether you're new to Linux or an advanced user seeking advanced tips, understanding .bashrc can greatly enhance your productivity. Let's learn how.

What is .bashrc?

The .bashrc file is a script that runs whenever you start a new terminal session in interactive mode. It is generally located in your home directory (~/.bashrc) and is used to configure your shell environment. This can include setting up aliases, functions, environment variables, and more.

In Ubuntu and other systems, you can also use the file ~/.bash_aliases. Read your ~/.bashrc to confirm.

How to use your .bashrc

Here are the primary aspects you can customize in your .bashrc file:

Aliases

Aliases are shortcuts for commands. Creating them can save you time and keystrokes.

$ alias ll='ls -la'
$ alias gs='git status'

Environment Variables

Environment variables are used to define settings and configuration options for applications. You can set variables like the PATH to include custom directories.

$ export PATH="$HOME/bin:$PATH"
$ export EDITOR='nano'

Custom Functions

You can define functions to automate tasks. For instance, a function that navigates to a frequently used directory.

function proj() {
  cd ~/projects/$1
}

Customize your Prompt

You can customize your terminal prompt to display useful information, such as the current user or directory.

$ PS1='[\u@\h \W]\$ '

Editing your .bashrc

Editing the ~/.bashrc file is straightforward. Use a text editor of your choice to modify it:

1. Open a terminal.

2. Use a text editor to open the file. For example:

$ nano ~/.bashrc # or ..
$ vim ~/.bashrc

3. Make your changes.

4. Save and exit the editor (in nano, press `CTRL + X`, then `Y`, and hit `Enter`. In Vim, <esc>:wq).

After making changes, you need to apply them for the current session. You can do this by "sourcing" the file:

$ source ~/.bashrc
The `source` command reloads the .bashrc file without needing to restart your terminal.

Example

Here’s an example of a simple .bashrc setup:

# Quick command shortcuts
alias ll='ls -la'
alias gs='git status'

# Custom functions
function proj() {
  cd ~/projects/$1
}

# Environment paths
export PATH="$HOME/bin:$PATH"
export EDITOR='nano'

# Prompt customization
PS1='[\u@\h \W]\$ '

Troubleshooting

If you encounter issues after modifying ~/.bashrc, you can revert to the previous version or comment out the problematic lines by adding a # in front.

Conclusion

The file ~/.bashrc is a powerful tool that can significantly improve your command-line experience. By leveraging its capabilities, you can streamline your workflow and make the terminal a more efficient environment for your tasks.

Start experimenting with your .bashrc today, and don’t hesitate to keep exploring new features and customizing your Linux system to maximize your productivity.

Wednesday, April 22, 2026

Understanding Package Managers in Linux

Package managers make managing software very easy and much simpler on Linux than on Macs or Windows PCs. Learn how...
Photo by Anastasiya Doicheva on Unsplash

Package managers make managing software very easy, making it much simpler to install software on Linux than it is on Macs or Windows PCs.

With package managers, both regular users and sysadmins have access to a simple process to install, upgrad, revert, and remove applications in Linux.

In this article, we'll explore the package managers associated with some of the most popular Linux distributions: Alpine, Debian/Ubuntu, Arch, RHEL, and SUSE.

Understanding Package Managers in Linux

Package managers are programs that allow users install and uninstall software packages efficiently, manage dependencies, and ensure that systems remain organized and secure.

The process behind package managers is simple. First, the user passes the name of a software package as an argument. The package manager then performs a lookup against a package repository to see whether that package exists. If it is found, the package manager installs the application defined by the package and its dependencies to the specified locations on the system.

Package managers can be divided into two categories: binary package managers, which handle precompiled binaries, and source package managers, which build software from source.

Each major Linux distribution often has its own package management system that is tailored to its unique needs. Let's see the most popular ones next.

Package Managers for Popular Distributions

Alpine (apk)

Alpine Package Keeper (apk) is a lightweight package manager designed for simplicity and speed. It uses .apk files and is focused on minimalism and security.

# Install a package
$ apk add <package>

# Remove a package
$ apk del <package>

# Search packages
$ apk search <keyword>

# Update the package index.
$ apk update

# Upgrade installed packages
$ apk upgrade

Debian/Ubuntu (apt)

Advanced Package Tool (apt) is a powerful command-line tool for managing packages. It works with .deb files and allows users to search for, install, and update software across repositories.

# Install a package
$ apt install <package>

# Remove a package
$ apt remove <package>

# Search packages
$ apt search <package>

# Update the package index
$ apt update

# Upgrade all installed packages
$ apt upgrade

Arch (pacman)

Pacman is the package manager for Arch Linux and its derivatives. It uses a simple syntax and manages both binary packages and the sources of the software. Pacman is known for its speed and simplicity.

# Install a package
$ pacman -S <package>

# Remove a package
$ pacman -R <package>

# Search packages
$ pacman -Ss <package>

# Synchronize and update the package database
$ pacman -Sy

# Upgrade all installed packages
$ pacman -Su

RHEL/CentOS (yum/dnf)

Yellowdog Updater Modified (yum) and Dandified YUM (dnf) are package managers for Red Hat-based distributions. They handle .rpm files and are known for their dependency resolution and repository management. DNF is the next-generation version of YUM.

# Install a package
$ yum install <package>
$ dnf install <package>

# Search packages
$ yum search <package>
$ dnf search <package>

# Remove a package
$ yum remove <package>
$ dnf update

SUSE (zypper)

Zypper is the command line package manager for SUSE, designed to manage .rpm packages and their dependencies effectively. It offers features such as delta RPMs, enabling faster downloads and updates. |

# Install a package
$ zypper install <package>

# Remove a package
$ zypper remove <package>

# Search packages
$ zypper search <package>

# Refresh the repository data
$ zypper refresh

# Upgrade all installed packages.
$ zypper update

Conclusion

Understanding package managers is crucial for effective Linux system management.

Each distribution has tailored its package manager, so if you use many distros, make sure you understand well the package manager for your distro.

Mastering these tools can significantly enhance your Linux experience, making software management seamless and efficient. As Linux continues to evolve, familiarity with these package managers will remain a valuable skill for users and administrators alike.

Featured Article

How Exports and Evironment Variables in Linux work

Environment variables play a crucial role in how Linux operates. Learn how to use them effectively. Photo by Abolfazl Pahlavan on Unspla...