Linux Virtual Machine on Windows with VMware
Note:
- The Linux system used is CentOS 7.
- This post is for mainland China developers, so the mirror used is from Aliyun.
Download Resources & Install VMware
First, download the VMware Workstation Pro and the Centos 7 mirror.
Centos 7 mirror provided by Aliyun
The downloaded files' names look like VMware-workstation-full-17.6.2-24409262.exe
and CentOS-7-x86_64-DVD-2207-02.iso
respectively.
Double click the downloaded VMware installer, and follow the instructions to install VMware.
Create Virtual Machine
Launch VMware, and select "create new virtual machine". Choose "Ordinary". In the next step, we are asked to choose a iso file. Find the .iso
file you downloaded just now, and click next. For the following steps, you can just use the default settings, or choose where to put your virtual machine.
Then, launch the virtual machine. There would be an installation process. Following the instructions would be ok. Remember to select installation destination in one of the steps. I also changed the settings about time zone and network in that step. Besides, you may want to set the root password and create users in the next step.
After the installation, you will be asked to reboot the machine.
Configure yum and Install Applications
First, backup the original repo by:
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
Then, download the new repo file (the example below is the repo provided by Aliyun):
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
Then, run these two commands:
yum clean all
yum makecache
It is also recommended to change http to https:
cd /etc/yum.repos.d
sudo vi CentOS-Base.repo
In the new window, type :%s/http/https/g
, and then type :wq
to save and exit.
Then:
sudo yum update
Now you can install some applications, such as git
.
sudo yum install git
Connect to Virtual Machine using SSH on the Physical Machine
Use the following commands to find the ip address of the virtual machine (the 4 groups of numbers following inet
):
sudo yum install -y net-tools
ifconfig | grep "inet 192.168."
Then you can use your physical device's ssh to connect to your virtual machine (replace yourusername
by your username and 192.168.xxx.xxx
by the ip address you got in the last step):
ssh yourusername@192.168.xxx.xxx
You can also use some ssh applications like PuTTY.
For Ubuntu
The Ubuntu above has a GUI, so it is easy and enough to just follow the instructions. Note that installation may take a long time (I used 1h 20mins >.<).