CLI Installation & Uninstallation
This chapter explains how to make your bash CLI accessible system-wide and how to uninstall it when needed. Imagine you've created a useful CLI tool and want to use it from anywhere in your terminal without navigating to its directory. This chapter will show you how.
Installing your CLI
This procedure describes how to install your bash CLI, making it globally accessible from your terminal. This involves creating a symbolic link to your cli entrypoint and setting up bash completion.
Prerequisites:
- A Bash CLI project initialized with the
initcommand (see Project Context & Validation). - Appropriate permissions to create files and directories in the target installation location (often
/usr/binand/etc/bash_completion.d).
Procedure:
-
Navigate to your project's root directory in the terminal.
-
Run the
install.shscript, providing the desired name for your CLI and optionally the installation folder (defaults to/usr/bin):
./app/install.sh <cli_name> [<installation_folder>]
For example:
./app/install.sh mycli
mycli to /usr/bin.
Or:
./app/install.sh mycli /usr/local/bin
mycli to /usr/local/bin.
Verification:
- Check that the symbolic link has been created:
ls -l <installation_folder>/<cli_name>. The output should show a link pointing to your project'sclifile. - Check that the bash completion script has been created:
cat /etc/bash_completion.d/<cli_name>.
Troubleshooting:
- Permission denied: Ensure you have the necessary permissions to write to the installation locations. Use
sudoif required. - "You are not within a Bash CLI project": Make sure you are running the script from the root of your Bash CLI project.
Uninstalling your CLI
This procedure details how to remove your CLI from the system.
Prerequisites:
- Your CLI should be currently installed.
- Appropriate permissions to remove files in the installation location (often
/usr/binand/etc/bash_completion.d).
Procedure:
-
Navigate to your project's root directory in the terminal.
-
Run the
uninstall.shscript, providing the name of your CLI and optionally the installation folder:
./app/uninstall.sh <cli_name> [<installation_folder>]
./app/uninstall.sh mycli
Verification:
- Verify that the symbolic link has been removed:
ls <installation_folder>/<cli_name>. The command should return an error indicating the file doesn't exist. - Verify that the bash completion script has been removed:
ls /etc/bash_completion.d/<cli_name>. The command should return an error.
Troubleshooting:
- Permission denied: Ensure you have the necessary permissions to remove files from the installation locations. Use
sudoif required. - "You are not within a Bash CLI project": Ensure you are running the script from the root of your Bash CLI project.
- "Command
did not exist in Double check the CLI name and installation folder." or "Command doesn't resolve to this project":
Internal Implementation
The install.sh script creates a symbolic link from your project's cli file to the specified installation directory (e.g., /usr/bin). It also sets up the bash completion script by writing the necessary commands to /etc/bash_completion.d/<cli_name>, sourcing the complete script (see Bash Completion Logic). The uninstall.sh script removes these files. Both scripts validate that they are running from within a valid Bash CLI project (see Project Context & Validation). They also ensure that the correct symbolic link is being operated on during uninstallation. The realpath function in both scripts resolves symbolic links to their absolute paths, ensuring correct file identification, even on systems like macOS, which might not have a built-in realpath command.
Conclusion
This chapter covered how to install and uninstall your Bash CLI, making it easily accessible or removing it from your system. Next Chapter Title
Generated by AI Codebase Knowledge Builder