Beginners Guide to Install Discourse on Ubuntu for Development

(Blake Erickson) #199

Yes, you can overwrite.

(Haseeb) #200

Can We Remove CREATE DATABASE steps and add rake db:create instead so that it will become,

bundle exec rake db:create db:migrate db:test:prepare db:seed_fu


Since the method detailed in Discourse as Your First Rails App, was no longer maintained for development Discourse setups, I had to try the process mentioned here. There were a few extra steps and learning curves that I had to go through before the setup could run successfully.

While creating ROLE, if the system username has a capitalized first letter (such as Techapj), then CREATE ROLE Techapj... will still create the role as lowercase techapj. This will mean that the user will not have a role associated with their actual system username and therefore will be unable to go further. This apparently can be resolved by using quotes, i.e. CREATE ROLE "Techapj"... (OR create a new lowercase username, switch accounts, add the new account to the sudoers file, which apparently can only be done after setting a password to the Ubuntu root account).

Another issue was the conflict in encoding types. For my instance, both the template0 and template1 were by default SQL_ASCII encoded. These had to be changed to UTF8 encoding. For this purpose, run the following:

sudo -u postgres psql postgres
UPDATE pg_database SET encoding = pg_char_to_encoding('UTF8') WHERE datname = 'template0';
UPDATE pg_database SET encoding = pg_char_to_encoding('UTF8') WHERE datname = 'template1';

For some reason, it didn’t work by only changing the encoding for template0. To list all databases with their properties, run: \list OR \l.

Additionally, rake commands throw out a cd error if the path contains whitespaces. Not sure how to resolve this. Another thing different from Discourse as Your First Rails App was that the Discourse instance, at least for me, used to open on localhost:4000 and now it opens in localhost:3000 (as it should).

(Arpit Jalan) #202

3 posts were split to a new topic: Database connection error when setting up Discourse development environment using Linux Bash Shell on Windows 10

(Irwin Binamungu) #203

This is the error i am getting when i run the ‘install bundle’ command.

An error occurred while installing pg (0.21.0), and
Bundler cannot continue.
Make sure that gem install pg -v '0.21.0' succeeds
before bundling.

(Blake Erickson) #204

I just ran into this too yesterday setting up pg on a new linux box. Try

sudo apt-get install libpq-dev

which should be the missing dependency pg needs to install.

(Jay Pfaffman) #205

So this needs to get added to the install script?

(Blake Erickson) #206

Yes. I just created a PR.

(Dakota) #207

this doesn’t seem to install all the dependencies right for me. i used $ bundle install but when doing $ bundle exec rake db:migrate db:test:prepare db:seed_fu i still get errors like

Could not find omniauth-github-1.3.0 in any of the sources
Run `bundle install` to install missing gems.

(yes i did try bundle installing again and even looked up the command line parameters for it but no use)
I tried installing some of them manually but there seem to be a lot missing. I’m not really experienced with Bundler, any clues?

(Blake Erickson) #208

I’m not really sure what is going on but I have a feeling it is related to ruby not loading the right path to your gems, or some sudo/non-sudo gem issue, or some other factor with your dev environment.

Can you run the following two commands and let us know what the output is, so that we can verify your ruby version and your gem path:

which ruby
env | grep GEM_PATH

Could you also tell us how you installed ruby on ubuntu? did you use apt-get, rvm, or rbenv?

(Dakota) #209
dakota@Cebes:~/discourse$ which ruby

The second command outputs nothing which I assume to be the problem.

I installed Ruby using $ rbenv install 2.4.2 and then switched to it but I already had another version installed before that (2.3.1 I think) that came with my system.

(Blake Erickson) #210

Have you restarted your computer/terminal? This way bash will pick up any new env settings.

Does this output anything?

gem env home

I don’t know much about rbenv, but the rbenv github page is pretty informative GitHub - rbenv/rbenv: Groom your app’s Ruby environment

Maybe also try the rbenv-doctor script?

(Andrew Schleifer) #211

How did you switch to it? Does ruby --version output 2.4.2?

(Dakota) #212

Hmm I’ll look into my installation I guess, something must be wrong there.

env /home/dakota/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0

Used $ rbenv global 2.4.2. Yes it does.

(Dakota) #213

sorted it out, i think! $ rbenv exec bundle install