When developing with Rails, I will write the preparation to the point where I start writing code. We will proceed with VirtualBox and Vagrant already installed. If you haven't installed VirtualBox and Vagrant yet, try searching on Google.
First, go to your desktop in the terminal.
$ cd Desktop
Then create a folder named "work" and move to that folder.
$ mkdir work
$ cd work
After that, create a folder name "vagrant" in the folder "work" and move to that folder.
$ mkdir vagrant
$ cd vagrant
Create a Vagrantfile in this folder called "vagrant".
$ vagrant init
This completes Vagrant's initial setup. Check in the terminal that it looks like the following.
Username: vagrant username$
Next, start Vagrant. From this point onward, I think it will be a task that is performed every time development is carried out.
Starting Vagrant is easy. Type the following command.
$ vagrant up
The very first startup takes a tremendous amount of time. You may eat rice and take a bath. Maybe you can watch a movie. If you've done that much, you'll probably be done when you realize it: baby:
When the first boot is complete
To the bottom,
With the words Your now on Rails!
A picture of a train: something like: steam_locomotive: appears.
This completes Vagrant startup.
Make an "SSH connection" to securely communicate with your PC in the virtual environment. Type the following command.
$ vagrant ssh
When connected correctly
[vagrant@localhost ~]$
It will be displayed like this.
The connection to the virtual environment is now complete.
Shared folders in your virtual environment are located in / home / vagrant / work
.
So move to that shared folder.
[vagrant@localhost ~]$ cd /home/vagrant/work
If the following is displayed, it means that you have moved.
[vagrant@localhost work]$
Use the rails new command
when creating a new application in Ruby on Rails.
To create an application called "sample", type as follows.
$ rails new sample
If this command is executed correctly, the sample folder will be created in the shared folder.
Select "Open" or "Open" from the file menu with VScode etc.
Select "Desktop"-> "work"-> "vagrant"-> "sample",
Open the sample folder
.
Once you have done this, type the following command to move to the sample directory you created earlier.
[vagrant@localhost work]$ cd sample
If the part that was "work" becomes "sample", it means that you can move it.
[vagrant@localhost sample]$
Now you are ready to start writing the code. At this point, you can start writing code.
Thank you for your hard work.
You may want to log out of the virtual environment and shut down the virtual environment every time you finish your work and before closing your computer.
With this command, you can log out from where you are "SSH connected".
[vagrant@localhost work]$ exit
Logout is complete when the following is displayed.
Username: vagrant username$
Next is the shutdown of the virtual environment. You can shut it down by typing the following command.
$ vagrant halt
If you want to shut down the virtual environment and start it again,
Start over with $ vagrant up
.
Thank you for watching until the end. Actually, I wrote it for myself in the future when I forgot.
I would be grateful if you could let me know if there are any mistakes.
I will continue to write articles for myself in the future and for those who happen to find my article and see it.
Recommended Posts