udacity / fullstack-nanodegree-vm

376 stars 11.78k forks source link

Not able to use 'psql' command in the virtual machine. #131

Open swilkinson423 opened 1 year ago

swilkinson423 commented 1 year ago

I'm working on the free Introduction to Relational Databases course, and I am stuck on the last section of the second module (Elements of SQL > Installing the Virtual Machine).

In the explanation it says I need to instal Vagrant and VirtualBox to set up a virtual machine and run PostgreSQL:

Installing the Virtual Machine

In the next part of this course, you'll use a virtual machine (VM) to run an SQL database server and a web app that uses it. The VM is a Linux server system that runs on top of your own computer. You can share files easily between your computer and the VM; and you'll be running a web service inside the VM which you'll be able to access from your regular browser.

We're using tools called Vagrant and VirtualBox to install and manage the VM. You'll need to install these to do some of the exercises. The instructions on this page will help you do this.

I am able to install both of these, and they run fine. The version of Vagrant is 2.3.4 and the version of VirtualBox is 7.0.4r154605.

Further down the page, it clearly states that the PostgreSQL server should be automatically available in the VM:

The files for this course

Inside the VM, change directory to /vagrant and look around with ls.

The files you see here are the same as the ones in the vagrant subdirectory on your computer (where you started Vagrant from). Any file you create in one will be automatically shared to the other. This means that you can edit code in your favorite text editor, and run it inside the VM.

Files in the VM's /vagrant directory are shared with the vagrant folder on your computer. But other data inside the VM is not. For instance, the PostgreSQL database itself lives only inside the VM.

Running the database

The PostgreSQL database server will automatically be started inside the VM. You can use the psql command-line tool to access it and run SQL statements:

[IMAGE OF PSQL RUNNING IN THE VIRTUAL MACHINE]

[IMG CAPTION]Running psql, the PostgreSQL command interface, inside the VM.

Here is where I run into a problem. I don't think it is actually installing or running PostgreSQL. When I type the 'psql' command, the commandline returns the following:

vagrant@vagrant:/vagrant$ psql
-bash: psql: command not found

Am I missing something? Was I supposed to install PostgreSQL myself? When I tried installing it myself, I could only install it on the local machine and don't know how to do so on the virtual machine...

jorboyce commented 2 weeks ago

I have a similar issue; psql returns -bash: psql: command not found.

Virtualbox version: 7.0.20 r163906 Vagrant version: 2.4.1 Ubuntu VM version: 21.4 (kernel 5.11.0-17-generic)

apt list --installed | grep postgresql returns nothing, suggesting that PostgreSQL is not installed at all. I also tried snap list, with similar results. A file named pg_config.sh, presumably a shell script that would configure PostgreSQL after installation, is shown in the tutorial inside of the /vagrant directory, but I can't find it there on my virtual machine.

Furthermore, the Python libraries used by forum.py don't seem to be installed either, preventing it from running.

If others are having the same issue, it seems like a user would have to install and configure PostgreSQL and Flask themselves in order to use the VM as intended? I'm not really experienced in doing either so I can't really help with that.