#!/bin/bash set -euo pipefail echo "============================================" echo "Neovim Latest Installation Script" echo "============================================" echo "" echo "This script will run the following commands with sudo:" echo " - apt-get update (if curl not installed)" echo " - apt-get install -y curl (if needed)" echo " - rm -rf /opt/nvim-linux64 (if old installation exists)" echo " - tar -C /opt -xzf nvim-linux64.tar.gz" echo "" read -p "Continue with installation? (y/N) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Installation cancelled." exit 0 fi echo "" echo "Starting installation (commands will be shown as they run)..." echo "" # Enable command tracing set -x # Check for required tools if ! command -v curl &> /dev/null; then sudo apt-get update sudo apt-get install -y curl fi # Disable tracing temporarily for cleaner download messages set +x # Download latest Neovim echo "Downloading Neovim..." TEMP_DIR=$(mktemp -d) cd "$TEMP_DIR" if ! curl -fsSL -o nvim-linux64.tar.gz https://github.com/neovim/neovim/releases/latest/download/nvim-linux64.tar.gz; then echo "Error: Failed to download Neovim" >&2 rm -rf "$TEMP_DIR" exit 1 fi echo "Download complete." set -x # Remove old installation if it exists if [ -d /opt/nvim-linux64 ]; then sudo rm -rf /opt/nvim-linux64 fi # Extract to /opt sudo tar -C /opt -xzf nvim-linux64.tar.gz set +x # Clean up cd - > /dev/null rm -rf "$TEMP_DIR" echo "" echo "============================================" # Verify installation if [ -x /opt/nvim-linux64/bin/nvim ]; then echo "Neovim installed successfully!" /opt/nvim-linux64/bin/nvim --version | head -n1 echo "" echo "Neovim is installed at: /opt/nvim-linux64/bin/nvim" echo "Add to PATH by adding this to your ~/.bashrc:" echo ' export PATH="$PATH:/opt/nvim-linux64/bin"' else echo "Error: Neovim installation failed" >&2 exit 1 fi echo "============================================"