[Fixed] “bash: curl: command not found” Error

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The “curl: command not found” error in Bash indicates that the cURL is either not installed or inaccessible. To fix this error, install “curl” using the system package manager. For example, run:

sudo apt install -y curl

The curl command is a powerful utility for making HTTP requests, commonly used in scripting and downloading files. Encountering “bash: curl: command not found” indicates that either the curl command-line tool is not installed on your system or the PATH variable is not set for curl. Let’s see the reasons for this error in detail and explore the possible fixes.

Reasons for “curl” Command Not Found Error

Some common reasons for “curl” command not found error are:

  • cURL not Installed: If you are unable to use the “curl” command, it could be that your system does not have cURL installed.
  • Incorrect Installation Path: The PATH on your system may not contain “curl”.
  • Inadequate Permissions: “curl” might not have the authorization it needs to function.
  • Binary Not Found: The curl binary might be missing or corrupted.
  • Incorrect Spelling: An error in command spelling raises the “command not found” error in Bash.

3 Methods to Solve “bash: curl: command not found” Error

Follow the below methods to solve the curl command not found error in Bash:

1. Install cURL

Most of the time, an incorrect installation of cURL on your system causes the “bash: curl: command not found” error. In this instance, APT in Ubuntu, YUM in RedHat, and Pacman in Arch Linux can install “curl” on your system with all its dependencies. To do that, follow the steps:

  1. Press CTRL+ALT+T to open the terminal in Ubuntu.
  2. Run the command to install curl in Ubuntu:
    sudo apt install -y curl

    installing curl in Ubuntu using APT

  3. Execute curl --version to verify the installation.executing curl --version command

Now, the curl command is executed successfully.

2. Set “curl” PATH Variable

A prevalent reason behind the “curl command not found” is cURL is not present in your system PATH environment variables. To set the PATH variable for “curl”, follow the steps below:

  1. Press CTRL+ALT+T to open the terminal.
  2. Use which command to check the current path of curl:
    which curl

    executing which curl command

  3. Open bashrc file using:
    nano ~/.bashrc
  4. Now, replace <path to curl> in export PATH=$PATH:<path to curl> code with the which command’s output and paste it at the end of the file. For example:

    export PATH=$PATH:/usr/bin/curl

    adding curl path variable to bashrc file

  5. Press CTRL+S to save, and CTRL+X to exit.
  6. Then, execute the .bashrc file using:
    source ~/.bashrc
  7. Now you can check running a curl command. For example:
    curl --version

    executing bashrc file and checking curl version

After adding the path, the curl command ran without raising any error.

3. Set an Alias to “curl”

To fix the “curl: command not found” error, you can create a temporary solution by setting up an alias for curl. Here’s how you can do it:

echo "alias curl='$(which curl)'" >> ~/.bashrc; . ~/.bashrc

This command appends an alias for the curl command to the ~/.bashrc file and immediately applies the changes in the current terminal session. The alias ensures that the curl command points to the correct path by using the $(which curl) syntax, which dynamically retrieves the actual path to the curl executable.

Note: You can execute the below command for a temporary fix:
cd /usr/local/bin; ln -s $(which curl) curl

Conclusion

In conclusion, resolving the “bash: curl: command not found” issue involves ensuring the installation of cURL and configuring the system’s PATH appropriately. Applying these solutions allows you to seamlessly access curl commands within the Bash environment and unlock the powerful capabilities of curl in making HTTP requests and downloading files.

People Also Ask

How to install curl in Linux?

To install curl, use a command from the below according to the Linux distribution you’re in:

  • Ubuntu/Debian: sudo apt install curl
  • Red Hat/Fedora: sudo yum install curl
  • Arch Linux/Manjaro: sudo pacman -S curl
  • openSUSE: sudo zypper install curl
  • Alpine Linux: sudo apk add curl

Why is curl command not found?

The “curl command not found” error typically occurs when the ‘curl’ executable is not installed or not in the system’s PATH. To resolve it, install curl using the appropriate package manager for your Linux distribution or ensure that the directory containing ‘curl’ is included in the PATH environment variable.

How to fix curl command not found in RHEL?

To fix the “curl command not found” issue on Red Hat Enterprise Linux (RHEL), use sudo yum install curl. Once the installation is complete, you should be able to use the ‘curl’ command without encountering the “command not found” error.

How to enable curl in Bash?

To enable curl in Bash:

  1. Install curl using your system’s package manager. For example, on Ubuntu/Debian:
    sudo apt-get install curl
  2. Verify the installation with:
    curl --version

Now you can use commands associated with curl.

How to solve “sudo: curl: command not found”?

To solve “sudo: curl: command not found” error in Linux, follow the steps:

  1. Run sudo visudo command to edit the sudoers file:
  2. Look for the line starting with secure_path and make sure it includes the directory where ‘curl’ is installed. For example:
    Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:<path to curl directory>

    Replace <path to curl directory> with the actual path of the ‘curl’ command. You can get it from which curl.

  3. Save and close the sudoers file.

Related Articles


<< Go Back to [Solved] “bash: command not found” Error | Bash Error Handling and Debugging | Bash Scripting Tutorial

Rate this post
Ashikur Rahman

Hello, I’m Ashikur Rahman, currently working as a Linux Content Developer Executive at SOFTEKO. I have completed my graduation in Computer Science and Engineering from Khulna University of Engineering & Technology (KUET). Also, I’m pursuing my master’s in the same department at Bangladesh University of Engineering & Technology (BUET). I like to learn new technologies, contribute, and share those with others. Here my goal is to provide beneficial and user-friendly articles on Linux distribution for everyone. Read Full Bio

Leave a Comment