Introduction
Vagrant is a software package that creates a standardized operating environment using virtualization technology.
Vagrant provides a command-line tool for loading and managing virtual operating systems. We will be using the VirtualBox provider in this tutorial.
This guide will walk you through installing Vagrant on CentOS 7.
Prerequisites
- A user account with sudo privileges on CentOS 7 system
- Access to a command line/terminal (Menu > Applications > Utilities > Terminal)
- The yum package manager, included by default
Install Vagrant on CentOS
Step 1: Refresh Software Repositories
In a terminal window, enter the command:
sudo yum update
The package manager will reach out to the repositories and refresh the listings. This ensures you are loading the most recent and patched versions of the software.
Step 2: Install VirtualBox
Vagrant is a tool that allows you to run an operating system inside an operating system. It does this by creating a virtual environment. Vagrant relies on an outside app (like VirtualBox) to manage virtual environments.
1. Start by installing the dependencies for VirtualBox. Enter the following into a terminal window:
sudo yum –y install epel-release
sudo yum –y install gcc dkms make qt libgomp patch
sudo yum –y install kernel-headers kernel-devel binutils glibc-headers glibc-devel font-forge
2. Next, add the software repository for VirtualBox:
sudo cd /etc/yum.repo.d/
sudo wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
3. Install the VirtualBox software:
sudo yum –y install VirtualBox-5.2
4. Verify that VirtualBox is installed with the command:
Virtualbox
The system should launch a new window welcoming you to VirtualBox.
There are other virtualization applications available. If you prefer, you could use KVM, VMware, or any other type of hypervisor software.
Note: If you opted to go with KVM, please refer to our tutorial on How To Install KVM on CentOS.
Step 3: Install Vagrant on CentOS
1. Open a web browser and browse to https://www.vagrantup.com/downloads.html. This page contains the most recent version of the software. At the time this article was written, Vagrant is at version 2.2.2.
2. In a terminal window, download the installation package by entering:
sudo wget https://releases.hashicorp.com/vagrant/2.2.2/vagrant_2.2.2_x86_64.rpm
The system should download the installation file. Adjust the version number and system architecture (32- or 64-bit) as needed for your system.
3. Install Vagrant on your CentOS machine with the command:
sudo yum –y localinstall vagrant_2.2.2_x86_64.rpm
Step 4: Verify Installation
To verify successful installation, display the version of Vagrant with the following command:
vagrant ––version
This is a quick way to make sure that the installation completed successfully. If you omit the double-hyphen, it will also include the latest available version.
Get Started With Vagrant on CentOS
1. To get started, you’ll need to create a directory to store your Vagrant files. In a terminal window, enter:
sudo mkdir ~/vagrant-centos-7
2. Switch to that directory with the command:
cd ~/vagrant-centos-7
3. Next, load a Vagrant box that you want to use. As an example, we’ll load a CentOS 7 file:
vagrant box add centos/7
4. Next, create a simple Vagrantfile. This is a text file with instructions for Vagrant to build out the virtual machine you want. Enter the command:
touch Vagrantfile
This should create a file Vagrantfile in the directory ~/vagrant-centos-7.
5. You can then launch the CentOS 7 virtual machine by entering:
vagrant up
The system should respond by telling you a “Vagrantfile” has been placed in the directory.
Note: You can also use the vagrant init command to initialize a virtual machine. The init command checks for a Vagrant file and creates one if not found. This can save you a couple of steps, especially if you’re running a default configuration. Use the init command after you create and switch to a directory. The init command is vagrant init centos/7
Basic Vagrant Commands
To create a virtual machine based on this file, enter:
vagrant up
The system will respond by displaying the default SSH address, username, and authentication method for the virtual machine it just created.
You can connect to your new virtual machine using SSH:
vagrant ssh
You can now work in a virtual CentOS 7 environment.
To stop your virtual machine use the command:
vagrant halt
To delete the virtual machine you just created, use the destroy command.
vagrant destroy
This will delete everything you’ve done inside that virtual machine.
Conclusion
Now, you know how to install and configure Vagrant on your CentOS 7 machine. Enjoy your new virtualized server!
Typically, this tool is used to duplicate an exact working environment. This can be particularly useful to a software development team to ensure code compatibility. For more information about Vagrant usage, please see the official Vagrant documentation site.
原创文章,作者:506227337,如若转载,请注明出处:https://blog.ytso.com/226140.html