Skip to content

Instantly share code, notes, and snippets.

@kiliczsh
Created May 25, 2025 16:07
Show Gist options
  • Select an option

  • Save kiliczsh/5bfd77a73b5eb37416de4a3847ac4bb5 to your computer and use it in GitHub Desktop.

Select an option

Save kiliczsh/5bfd77a73b5eb37416de4a3847ac4bb5 to your computer and use it in GitHub Desktop.
Ruby Environment Diagnostic Script
#!/bin/bash
# Ruby Environment Diagnostic Script
# This script checks your Ruby installation and identifies potential issues
echo "πŸ” Ruby Environment Diagnostic Report"
echo "======================================"
echo "Date: $(date)"
echo "User: $(whoami)"
echo "======================================"
# System Information
echo -e "\nπŸ“± SYSTEM INFORMATION"
echo "----------------------"
uname -a
echo "macOS Version: $(sw_vers -productVersion)"
echo "Architecture: $(uname -m)"
# Check if Homebrew is installed
echo -e "\n🍺 HOMEBREW STATUS"
echo "-------------------"
if command -v brew &> /dev/null; then
echo "βœ… Homebrew installed: $(brew --version | head -1)"
echo "Homebrew prefix: $(brew --prefix)"
else
echo "❌ Homebrew not found"
fi
# Check Ruby installations
echo -e "\nπŸ’Ž RUBY INSTALLATIONS"
echo "----------------------"
echo "System Ruby:"
echo " Path: $(which ruby 2>/dev/null || echo 'Not found')"
echo " Version: $(ruby -v 2>/dev/null || echo 'Not available')"
# Check if multiple Ruby installations exist
echo -e "\nAll Ruby installations found:"
find /usr/bin /usr/local/bin /opt/homebrew/bin ~/.rbenv ~/.asdf ~/.rvm -name "ruby" -type f 2>/dev/null | while read ruby_path; do
if [ -x "$ruby_path" ]; then
version=$($ruby_path -v 2>/dev/null || echo "unknown")
echo " $ruby_path -> $version"
fi
done
# Check Ruby version managers
echo -e "\nπŸ”§ RUBY VERSION MANAGERS"
echo "-------------------------"
# Check rbenv
if command -v rbenv &> /dev/null; then
echo "βœ… rbenv found:"
echo " Version: $(rbenv --version)"
echo " Root: $(rbenv root 2>/dev/null || echo 'unknown')"
echo " Installed versions:"
rbenv versions 2>/dev/null | sed 's/^/ /'
echo " Current: $(rbenv version 2>/dev/null || echo 'none set')"
else
echo "❌ rbenv not found"
fi
# Check asdf
if command -v asdf &> /dev/null; then
echo "βœ… asdf found:"
echo " Version: $(asdf version)"
echo " Ruby plugin installed: $(asdf plugin list | grep ruby || echo 'No')"
if asdf plugin list | grep -q ruby; then
echo " Installed Ruby versions:"
asdf list ruby 2>/dev/null | sed 's/^/ /' || echo " None installed"
echo " Current Ruby: $(asdf current ruby 2>/dev/null || echo 'none set')"
fi
else
echo "❌ asdf not found"
fi
# Check RVM
if command -v rvm &> /dev/null; then
echo "βœ… RVM found:"
echo " Version: $(rvm --version | head -1)"
echo " Installed versions:"
rvm list 2>/dev/null | sed 's/^/ /'
echo " Current: $(rvm current 2>/dev/null || echo 'none set')"
else
echo "❌ RVM not found"
fi
# Check PATH
echo -e "\nπŸ›€οΈ PATH ANALYSIS"
echo "-----------------"
echo "Current PATH:"
echo "$PATH" | tr ':' '\n' | nl
echo -e "\nRuby-related paths in PATH:"
echo "$PATH" | tr ':' '\n' | grep -E "(ruby|rbenv|asdf|rvm)" | nl
# Check environment variables
echo -e "\n🌍 ENVIRONMENT VARIABLES"
echo "------------------------"
env | grep -i ruby | while read var; do
echo " $var"
done
if [ -z "$(env | grep -i ruby)" ]; then
echo " No Ruby-related environment variables found"
fi
# Check shell configuration
echo -e "\n🐚 SHELL CONFIGURATION"
echo "----------------------"
echo "Current shell: $SHELL"
# Check common shell config files
for config_file in ~/.bashrc ~/.bash_profile ~/.zshrc ~/.zsh_profile ~/.profile; do
if [ -f "$config_file" ]; then
echo "Checking $config_file:"
if grep -E "(ruby|rbenv|asdf|rvm)" "$config_file" &> /dev/null; then
echo " Ruby-related configurations found:"
grep -E "(ruby|rbenv|asdf|rvm)" "$config_file" | sed 's/^/ /'
else
echo " No Ruby-related configurations found"
fi
fi
done
# Check gems
echo -e "\nπŸ’ GEMS STATUS"
echo "--------------"
if command -v gem &> /dev/null; then
echo "βœ… gem command available:"
echo " Version: $(gem -v)"
echo " Installation paths:"
gem env | grep -A 10 "GEM PATHS" | sed 's/^/ /'
echo " Installed gems count: $(gem list --local | wc -l)"
else
echo "❌ gem command not available"
fi
# Check bundler
echo -e "\nπŸ“¦ BUNDLER STATUS"
echo "-----------------"
if command -v bundle &> /dev/null; then
echo "βœ… Bundler available:"
echo " Version: $(bundle -v)"
echo " Path: $(which bundle)"
else
echo "❌ Bundler not available"
fi
# Check for common issues
echo -e "\n⚠️ POTENTIAL ISSUES"
echo "--------------------"
# Check if using system Ruby
current_ruby=$(which ruby 2>/dev/null)
if [[ "$current_ruby" == "/usr/bin/ruby" ]]; then
echo "⚠️ Using system Ruby (not recommended for development)"
fi
# Check Ruby version
ruby_version=$(ruby -v 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1)
if [[ -n "$ruby_version" ]]; then
major_version=$(echo "$ruby_version" | cut -d. -f1)
minor_version=$(echo "$ruby_version" | cut -d. -f2)
if [[ "$major_version" -lt 3 ]] || [[ "$major_version" -eq 2 && "$minor_version" -lt 7 ]]; then
echo "⚠️ Ruby version $ruby_version is outdated (EOL)"
fi
fi
# Check for conflicting installations
ruby_paths=($(find /usr/bin /usr/local/bin /opt/homebrew/bin ~/.rbenv ~/.asdf ~/.rvm -name "ruby" -type f 2>/dev/null))
if [[ ${#ruby_paths[@]} -gt 1 ]]; then
echo "⚠️ Multiple Ruby installations detected - may cause conflicts"
fi
# Check if version manager is properly initialized
if command -v rbenv &> /dev/null; then
if ! echo "$PATH" | grep -q rbenv; then
echo "⚠️ rbenv found but not in PATH - may need shell configuration"
fi
fi
if command -v asdf &> /dev/null; then
if ! echo "$PATH" | grep -q asdf; then
echo "⚠️ asdf found but not in PATH - may need shell configuration"
fi
fi
# Recommendations
echo -e "\nπŸ’‘ RECOMMENDATIONS"
echo "------------------"
if [[ "$current_ruby" == "/usr/bin/ruby" ]]; then
echo "1. Install a Ruby version manager (rbenv or asdf recommended)"
echo "2. Install a modern Ruby version (3.3.x or 3.4.x)"
fi
if ! command -v rbenv &> /dev/null && ! command -v asdf &> /dev/null && ! command -v rvm &> /dev/null; then
echo "1. Install a Ruby version manager:"
echo " - rbenv: brew install rbenv ruby-build"
echo " - asdf: brew install asdf && asdf plugin add ruby"
fi
if command -v asdf &> /dev/null && ! asdf plugin list | grep -q ruby; then
echo "1. Add Ruby plugin to asdf: asdf plugin add ruby"
fi
echo -e "\nβœ… Diagnostic complete!"
echo "Save this output and share it for further assistance if needed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment