Install Uncomment to Remove Code Comments on Ubuntu 26.04

Install Uncomment to Remove Code Comments on Ubuntu 26.04

Uncomment is a lightweight command-line tool designed for removing comments from source files. It supports many languages and is commonly used to clean configuration files and scripts by stripping out unnecessary comments while preserving functional code. It can also be useful for cleaning up AI-generated code with excessive comments. This tutorial shows how to install Uncomment on Ubuntu 26.04.

Install Uncomment

Download the latest release archive directly from the official GitHub repository and extract binary into a directory included in the system PATH:

curl -sSL https://github.com/Goldziher/uncomment/releases/latest/download/uncomment-x86_64-unknown-linux-gnu.tar.gz \
  | sudo tar xz -C /usr/local/bin uncomment

Confirm successful setup by checking Uncomment version:

uncomment --version

Testing Uncomment

A sample Python file demonstrates how comments are removed while keeping functional code intact. Create a file:

nano main.py

Add the code with comments:

# Simple function
def greet(name):
    # Say hello
    print(f"Hello {name}")

greet('world')

Run the command to remove comments:

uncomment main.py

Check the updated file:

cat main.py

Result after processing:

def greet(name):
    print(f"Hello {name}")

greet('world')

All comment lines are removed while executable logic remains unchanged.

Uninstall Uncomment

To remove Uncomment from the system, delete the installed binary:

sudo rm -rf /usr/local/bin/uncomment

Leave a Comment

Cancel reply

Your email address will not be published.