mkdir -p ~/Sites/sfh
cd ~/Sites/sfh
vagrant init ubuntu/<codename>64
mkdir C:\sfh
cd C:\sfh
vagrant init ubuntu/<codename>64
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/<codename>64"
end
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/<codename>64"
config.vm.network :private_network, ip: "192.168.33.10"
end
Notes :
The private_network directive tells Vagrant to setup a private network. PC host and guest machines can communicate on this network. This assigns the guest server the IP address of 192.168.33.10
. Note that each server should have a unique IP address just in case they are run at the same time.
There are IP address ranges set aside for private networks. Generally we can use 10.0.0.0
- 10.255.255.255
, 172.16.0.0
- 172.31.255.255
, and 192.168.0.0
- 192.168.255.255
. However, always avoid the lower and upper IP addresses within those ranges, as they are often reserved.
This will download the ubuntu/
vagrant up
Once it completed check the status
vagrant status
Run vagrant ssh to log into the server
vagrant ssh
ls -alF
, this will list all files within the current directoryctrl+c
keyboard shortcut to return to the prompt.A Vagrantfile with the default file sharing configuration in place. This allows us to edit files from our host machine while running the server software within our guest server:
#File: Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/<codename>64"
config.vm.network :private_network, ip: "192.168.33.10"
# Share Vagrantfile's directory on the host with /vagrant on the guest
config.vm.synced_folder ".", "/vagrant"
end
List the contents of the /vagrant directory within server:
ls -la /vagrant
create a new text file in βΌ/Sites/sfh named hello.txt:
echo "Hello World" > ~/Sites/sfh/hello.txt
# See files in /vagrant
cd /vagrant
ls -la
# Output the content of "hello.txt"
# with the "cat" command
# Output: "Hello World"
cat /vagrant/hello.txt
check out the network configuration.
ifconfig
The result, each network is called an βinterfaceβ.
127.0.0.1
.192.168.22.10
. The server also has its own private network, with the IP address 10.0.2.15
assigned to this machine.# List contents of current working directory
ls
# List contents in a list form, with extra information:
ls -l
# List contents, including "hidden" files/folders
ls -la
# Add human-readable file/folder sizes:
ls -lah
# Change into the "/home/user/sites/sfh" directory.
cd /home/user/sites/sfh
# Same as above, but with the "~" shortcut
# to the current users home directory
cd ~/sites/sfh
# Create the `sfh` directory
# inside of /home/user/sites/sfh
mkdir ~/sites/sfh
# Create the /home/user/sites/sfh directory and
# any directory in between that doesn't exist
mkdir -p ~/sites/sfh
# Delete (permanently) the `file.ext` file.
rm /path/to/file.ext
# Delete (recursively) the `/path/to/directory` directory.
rm -r /path/to/directory
# the additional `f` flag is to "force" the action,
# without prompting to make sure you want to do it.
# This is dangerous.
rm -rf /path/to/directory
sudo apt-get install curl wget unzip git ack-grep htop vim tmux software-properties-common