How to Install and Configure Git on Your VPS
Step 1: Log in to Your VPS
- Open your SSH client (e.g., PuTTY, Terminal) and log in to your VPS using your root credentials.
Step 2: Update Your Package List
- It is important to update your package list before installing any new software. Run the following command:
sudo apt update
- This ensures that your system package list is up to date.
Step 3: Install Git
- To install Git on your VPS, run the following command:
sudo apt install git
- Confirm the installation by typing
Y
when prompted.
Step 4: Verify the Git Installation
- After the installation is complete, verify that Git has been successfully installed by running:
git --version
- This will display the installed Git version.
Step 5: Configure Git
- Set your username in Git with the following command:
git config --global user.name "Your Name"
- Replace "Your Name" with your preferred username.
- Set your email address for Git commits with the following command:
git config --global user.email "youremail@example.com"
- Replace "youremail@example.com" with your actual email address.
Step 6: Configure Git Editor (Optional)
- If you want to configure a default editor for Git (e.g., nano, vim), use the following command:
git config --global core.editor nano
- Replace
nano
with your preferred editor if needed.
Step 7: Confirm Your Configuration
- To verify your Git configuration settings, run the following command:
git config --list
- This will display the configured username, email, and editor settings.
Step 8: Set Up SSH Keys (Optional)
- If you want to interact with Git repositories securely using SSH, generate an SSH key by running:
ssh-keygen -t rsa -b 4096 -C "youremail@example.com"
- Press Enter to accept the default file location, and set a passphrase when prompted.
- To view your SSH public key, use the command:
cat ~/.ssh/id_rsa.pub
- Copy the SSH key and add it to your Git hosting service (e.g., GitHub, GitLab).
After configuring Git, you can now use it to clone repositories, commit changes, and push to remote servers. Always keep your Git configuration secure, especially your SSH keys.