When installing custom Bash scripts like Leiningen for Clojure development, it's crucial to follow Linux filesystem conventions. The Filesystem Hierarchy Standard (FHS) defines specific purposes for each directory:
/usr/local/bin - For scripts installed locally by the system administrator
/opt - For third-party application packages
/usr/bin - For distribution-managed executables (avoid for custom scripts)
/home/username/bin - For user-specific scripts (not system-wide)
For system-wide availability of your Bash scripts, consider these options:
# Option 1: /usr/local/bin (most common for admin-installed tools)
sudo install lein /usr/local/bin/
# Option 2: /opt (better for complex applications with multiple files)
sudo mkdir -p /opt/leiningen/
sudo install lein /opt/leiningen/
sudo ln -s /opt/leiningen/lein /usr/local/bin/lein
After installation, ensure your script is in the system's PATH:
# Check current PATH
echo $PATH
# If using /opt, you might need to add to PATH
echo 'export PATH=$PATH:/opt/leiningen' | sudo tee /etc/profile.d/leiningen.sh
chmod +x /etc/profile.d/leiningen.sh
Proper permissions are essential for security:
# Set appropriate ownership
sudo chown root:root /usr/local/bin/lein
# Set executable permissions
sudo chmod 755 /usr/local/bin/lein
Test your installation works system-wide:
# As regular user
which lein
lein --version
# Check permissions
ls -l /usr/local/bin/lein
For single-user systems, ~/.local/bin is also acceptable:
mkdir -p ~/.local/bin
install lein ~/.local/bin/
echo 'export PATH=$PATH:~/.local/bin' >> ~/.bashrc
source ~/.bashrc
Remember to document your installation:
- Create a README in /opt/leiningen/ if using that location
- Consider creating an uninstall script
- Track versions if you maintain multiple releases
When installing custom Bash scripts like Leiningen for system-wide use, it's crucial to understand the Linux Filesystem Hierarchy Standard (FHS). The main directories to consider are:
/usr/local/bin # Primary location for local system executables
/usr/bin # System-wide command binaries
/opt # For add-on application software packages
~/.local/bin # User-specific binaries (requires PATH modification)
For Leiningen or similar custom scripts, here are the most appropriate locations:
- /usr/local/bin - The standard choice for locally installed software:
sudo install lein /usr/local/bin/
- /opt - Better for more complex installations with multiple files:
sudo mkdir /opt/leiningen sudo install lein /opt/leiningen/ sudo ln -s /opt/leiningen/lein /usr/local/bin/lein
After installation, verify the script is in your PATH:
echo $PATH
which lein
If using ~/.local/bin, add this to your .bashrc or .zshrc:
export PATH="$HOME/.local/bin:$PATH"
Here's the complete process for Leiningen:
# Download the script
wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
# Make it executable
chmod +x lein
# Install to recommended location
sudo mv lein /usr/local/bin/
# First run to bootstrap
lein
Maintain proper permissions:
sudo chown root:root /usr/local/bin/lein
sudo chmod 755 /usr/local/bin/lein