I recommend you use VirtualBox to create a virtual machine. This is best because it sandboxes your development environment and you get a real Linux environment to work in. VirtualBox is free and open source and you probably won't need any advanced features you might see in VMWare or Parallels.
Now that you have the environment built you can create a directory where your project folders go. From the prompt just do mkdir projects
, cd projects
, mkdir helloworld
, cd helloworld
. Then, you can use the built-in editor nano
to edit files. Type nano hello.c
and then enter the following:
#include <stdio.h>
int main()
{
printf("Hello, world\n");
}
Then type Ctrl-O
to write out and then Ctrl-X
to exit.
Then you just need to install gcc
and I would suggest installing make
as well:
$ sudo apt install gcc
...
$ sudo apt install make
Now to compile and test your first program in your development environment:
$ make hello
$ ./hello
Then you should see Hello, world
on your screen.
Valgrind and Un-mount Disk
From your helloworld
project folder enter sudo apt install valgrind
, then run valgrind ./hello
.
Finally, go to Settings -> Storage and un-mount the installation ISO.
SSH Access
Install openssh-server
using the following command:
sudo apt install openssh-server
Find the IP address of your Ubuntu host by typing ifconfig
. Then for VirtualBox go to Settings
:: Network
:: Advanced
and click Port Forwarding
. Use these settings:
Host IP: 127.0.0.1
Host Port: 22
Guest IP: (IP of Ubuntu VM)
Guest Port: 22
Now you can ssh
to your Ubuntu VM and also use tools like scp
.
Shared Folders
Shared folders allow you to have a medium that spans both file systems, allowing you to share files between the two environments. This resource offers a lot more detail in the different methods: https://www.virtualbox.org/manual/ch04.html#sharedfolders. I will go over how to set this up quickly in the setup detailed here.
The following will install the Linux headers required for VirtualBox shared folders:
sudo apt-get install build-essential linux-headers-`uname –r`
Then go to the Devices
tab of the VirtualBox menu and click Insert Guest Additions CD image...
.
Now we need to mount
the cdrom
and run the script:
sudo mount /dev/cdrom /media/cdrom
sudo /media/cdrom/VBoxLinuxAdditions.run
Figure out what Windows folder you want to share, and share it by going to VirtualBox guest Machine
:: Settings
:: Shared Folders
and add it with the options Auto-mount
and Make Permanent
. When you're done, do a sudo reboot
.
The shared folders are automatically added and exist in /media/sf_*
.
You must be in the vboxsf
group to work with those files. Use this command to add a user testuser
to that group:
sudo usermod -aG vboxsf testuser
sudo reboot