Skip to content

Instantly share code, notes, and snippets.

@malcohelper
Last active June 13, 2025 08:20
Show Gist options
  • Save malcohelper/94b61cead0aaea046afe39a24b9863bb to your computer and use it in GitHub Desktop.
Save malcohelper/94b61cead0aaea046afe39a24b9863bb to your computer and use it in GitHub Desktop.
setup_env_react_native

Setup Environment React Native by ONE Script

setup_env

FlowChart Untitled diagram-2025-02-21-063607

This script automates the installation and setup of the essential development environment on macOS, including:

  • Homebrew
  • RVM (Ruby Version Manager) and Ruby
  • NVM (Node Version Manager) and Node.js
  • Bundler and Cocoapods
  • Yarn
  • Xcode Command Line Tools

Prerequisites

Make sure you have the following:

  • A macOS system with internet access
  • Terminal access

Installation

  1. Make the script executable:

    chmod +x setup_env_react_native.sh
  2. Run the script:

    ./setup_env_react_native.sh
  3. Follow the on-screen instructions: The script will prompt you to enter the Ruby and Node.js versions you want to install. Press Enter to use the default versions.

Post Installation

Once the script completes, you can verify installations with:

ruby -v    # Check Ruby version
node -v    # Check Node.js version
yarn -v    # Check Yarn version
pod --version  # Check Cocoapods version

If you run into any issues, restart your terminal or run:

source ~/.zshrc

Troubleshooting

  • If Homebrew is not found, try running:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • If RVM is not detected, restart your terminal and try:
    source /opt/homebrew/share/rvm/scripts/rvm
  • If NVM does not load properly, run:
    source ~/.zshrc

Uninstallation

To remove installed tools, use the following:

brew uninstall rvm nvm
rvm implode
nvm uninstall <node_version>
gem uninstall cocoapods bundler

๐Ÿš€ Malco Helper!

#!/bin/bash
# Get Ruby and Node versions from user input or use defaults
read -p "Enter Ruby version (default: 3.2.0): " ruby_version
ruby_version=${ruby_version:-3.2.0}
read -p "Enter Node.js version (default: 18): " node_version
node_version=${node_version:-18}
echo -e "\033[1;34m๐Ÿ”น Using Ruby: $ruby_version, Node.js: $node_version\033[0m"
# Check Homebrew
if ! command -v brew &>/dev/null; then
echo -e "\033[1;33m๐Ÿ”น Installing Homebrew...\033[0m"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo -e "\033[1;32mโœ… Homebrew is already installed.\033[0m"
fi
# Ensure Homebrew environment is set up
eval "$(/opt/homebrew/bin/brew shellenv)"
# Install RVM manually if not available
if ! command -v rvm &>/dev/null; then
echo -e "\033[1;33m๐Ÿ”น Installing RVM...\033[0m"
curl -sSL https://get.rvm.io | bash -s stable
source "$HOME/.rvm/scripts/rvm"
else
echo -e "\033[1;32mโœ… RVM is already installed.\033[0m"
fi
# Ensure RVM is sourced in ~/.zshrc
if ! grep -q 'source "$HOME/.rvm/scripts/rvm"' ~/.zshrc; then
echo 'export PATH="$PATH:$HOME/.rvm/bin"' >> ~/.zshrc
echo 'source "$HOME/.rvm/scripts/rvm"' >> ~/.zshrc
fi
source "$HOME/.rvm/scripts/rvm"
# Install Ruby if not available
if ! rvm list strings | grep -q "$ruby_version"; then
echo -e "\033[1;33m๐Ÿ”น Installing Ruby $ruby_version...\033[0m"
rvm install "$ruby_version"
fi
rvm use "$ruby_version" --default
# Install NVM via Homebrew
if ! brew list nvm &>/dev/null; then
echo -e "\033[1;33m๐Ÿ”น Installing NVM via Homebrew...\033[0m"
brew install nvm
else
echo -e "\033[1;32mโœ… NVM is already installed via Homebrew.\033[0m"
fi
# Ensure NVM is sourced in ~/.zshrc
if ! grep -q 'export NVM_DIR="$HOME/.nvm"' ~/.zshrc; then
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.zshrc
echo '[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh"' >> ~/.zshrc
echo '[ -s "/opt/homebrew/opt/nvm/etc/bash_completion" ] && . "/opt/homebrew/opt/nvm/etc/bash_completion"' >> ~/.zshrc
fi
# Load NVM
export NVM_DIR="$HOME/.nvm"
source "/opt/homebrew/opt/nvm/nvm.sh"
# Install Node.js if not available
if ! nvm list | grep -q "v$node_version"; then
echo -e "\033[1;33m๐Ÿ”น Installing Node.js $node_version...\033[0m"
nvm install "$node_version"
fi
nvm use "$node_version"
nvm alias default "$node_version"
# Install Bundler if not available
if ! gem list -i bundler &>/dev/null; then
echo -e "\033[1;33m๐Ÿ”น Installing Bundler...\033[0m"
gem install bundler
else
echo -e "\033[1;32mโœ… Bundler is already installed.\033[0m"
fi
# Install Cocoapods if not available
if ! gem list -i cocoapods &>/dev/null; then
echo -e "\033[1;33m๐Ÿ”น Installing Cocoapods...\033[0m"
gem install cocoapods
else
echo -e "\033[1;32mโœ… Cocoapods is already installed.\033[0m"
fi
# Install Yarn if not available
if ! command -v yarn &>/dev/null; then
echo -e "\033[1;33m๐Ÿ”น Installing Yarn...\033[0m"
npm install -g yarn
else
echo -e "\033[1;32mโœ… Yarn is already installed.\033[0m"
fi
# Install Zulu JDK if not available
if ! brew list --formula | grep -q "zulu"; then
echo -e "\033[1;33m๐Ÿ”น Installing Zulu JDK...\033[0m"
brew install --cask zulu@17
else
echo -e "\033[1;32mโœ… Zulu JDK is already installed.\033[0m"
fi
# Ensure Zulu JDK is sourced in ~/.zshrc
if ! grep -q 'export JAVA_HOME="$(/usr/libexec/java_home -v 17)"' ~/.zshrc; then
echo 'export JAVA_HOME="$(/usr/libexec/java_home -v 17)"' >> ~/.zshrc
echo 'export ANDROID_HOME="$HOME/Library/Android/sdk"' >> ~/.zshrc
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin:$PATH"' >> ~/.zshrc
fi
# Check for Xcode Command Line Tools
if ! xcode-select -p &>/dev/null; then
echo -e "\033[1;33m๐Ÿ”น Installing Xcode Command Line Tools...\033[0m"
xcode-select --install
else
echo -e "\033[1;32mโœ… Xcode Command Line Tools are already setup.\033[0m"
fi
# Check if Xcode Command Line Tools is already installed
if xcode-select -p &>/dev/null; then
echo "โœ… Xcode Command Line Tools is already set up."
osascript -e 'display notification "Xcode Command Line Tools is already installed!" with title "Setup Complete"'
else
echo "๐Ÿ”น Xcode Command Line Tools is not set up."
# Show a dialog to request permission
osascript -e 'display dialog "Xcode Command Line Tools needs permission to be set up. Click OK to continue." buttons {"OK"} default button "OK" with icon caution'
# Install Xcode Command Line Tools
xcode-select --install
# Wait for user confirmation
osascript -e 'display notification "Please complete the installation and click OK when done." with title "Installation in Progress"'
# Verify if installation was successful
if xcode-select -p &>/dev/null; then
osascript -e 'display notification "Xcode Command Line Tools has been successfully installed!" with title "Setup Complete"'
echo "\033[1;32mโœ… Xcode Command Line Tools has been setup.\033[0m"
else
osascript -e 'display alert "Error!" message "Failed to set up Xcode Command Line Tools. Please try again manually."'
echo "โŒ Error: Could not set up Xcode Command Line Tools."
fi
fi
# Display installed versions
echo -e "\n\033[1;36m๐Ÿ“Œ Installation Complete!\033[0m"
echo -e "\033[1;35m--------------------------------\033[0m"
echo -e "๐Ÿบ \033[1;34mHomebrew:\033[0m $(brew --version | head -n 1)"
echo -e "๐Ÿ’Ž \033[1;34mRuby:\033[0m $(ruby -v)"
echo -e "๐Ÿ“ฆ \033[1;34mRVM:\033[0m $(rvm -v | head -n 1)"
echo -e "๐Ÿš€ \033[1;34mNVM:\033[0m $(nvm --version)"
echo -e "๐Ÿ“Œ \033[1;34mNode.js:\033[0m $(node -v)"
echo -e "๐Ÿ›  \033[1;34mBundler:\033[0m $(bundler -v)"
echo -e "๐Ÿ“ฆ \033[1;34mCocoapods:\033[0m $(pod --version)"
echo -e "๐Ÿงถ \033[1;34mYarn:\033[0m $(yarn -v)"
echo -e "๐Ÿงถ \033[1;34mJava:\033[0m $(java -version)"
echo -e "๐Ÿ–ฅ \033[1;34mXcode:\033[0m $(xcodebuild -version | head -n 1)"
echo -e "\033[1;35m--------------------------------\033[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment