Created
May 25, 2025 16:07
-
-
Save kiliczsh/5bfd77a73b5eb37416de4a3847ac4bb5 to your computer and use it in GitHub Desktop.
Ruby Environment Diagnostic Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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