<!-- TOC START -->
Table of Contents
RailsGirls installation scripts
NodeJS and npm
Install Node via NVM.
See: NodeJS proper installation
$ curl https://raw.githubusercontent.com/creationix/nvm/v0.22.2/install.sh | bash
Restart terminal shell
$ nvm install 0.10 --or -- nvm install stable
To use NodeJS
$ nvm use stable
To set a default Node version to be used in any new shell, use the alias 'default':
$ nvm alias default stable
Test node installation
// hello_node.js var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Node.js\n'); }).listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/');
Production server with Unicorn & nginx
Uninstall RVM
sudo rvm implode sudo rm -rf /etc/rvmrc /etc/profile.d/rvm.sh /usr/local/rvm
Install RVM & Ruby
Add user to sudoers list
usermod -a -G wheel alfredo => alfredo is sudoer
rvm ⇒ ver instrucciones en https://rvm.io/
Source: http://railsapps.github.io/installrubyonrails-ubuntu.html
$ \curl -L https://get.rvm.io | bash -s stable --ruby
If it fails, follow the given instruction to download keys and try again.
Reopen terminal shell.
Generate ri documentation (recomended)
$ rvm docs generate-ri
https://coderwall.com/p/ttrhow/deploying-rails-app-using-nginx-puma-and-capistrano-3 Install rvm, ruby and rubygems:
curl -L get.rvm.io | bash -s stable source ~/.rvm/scripts/rvm rvm requirements rvm install 2.1.0 rvm use 2.1.0 --default rvm rubygems current
Upgrade rvm
rvm get head
Integrating RVM with Gnome-terminal
For RVM to work properly, you have to check the 'Run command as login shell' checkbox on the Title and Command tab of gnome-terminal's Edit ▸ Profile Preferences menu dialog, in case the menu is missing right click the terminal app and navigate Profiles ▸ Profile Preferences.
Recomended install gem nokogiri (Rails install Nokogiri)
This is a basic gem that many others depend on and it takes time to install it. So, it's recomended install it in advance in the global gemset:
$ gem install nokogiri
Rails
$ gem install rails
Gemsets
Create new gemset for the application
rvm gemset create <appname> rvm gemset use <appname>
Remove gemset:
rvm gemset delete <name>
It is a good idea to use RVM, the Ruby Version Manager, and create a project-specific rvm gemset.
$ rvm gemset list $ rvm gemset use global
To list the gems installed by RVM:
rvm all do gem list rvm <ruby version> do gem list
To list the gems installed by bundle in the application:
bundle list
Create configurations files .ruby-version & .ruby-gemset
Source: https://rvm.io/workflow/projects#project-file-ruby-version
To create both files in the project folder:
$ rvm --ruby-version use 2.2.0@my_app --create
Use the corresponding Ruby versión and app name. Append –create if the gems doesn't exist yet.
Postgres gem in fedora
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
yum install /usr/include/libpq-fe.h
Updating an existing app
- Create .ruby-version and .ruby-gemset files
- Change Ruby versión in Gemfile
- Bundle update
Update GEMs
Source: http://ilikestuffblog.com/2012/07/01/you-should-update-one-gem-at-a-time-with-bundler-heres-how/
Update only one gem
bundle update ––source gemname
Update one gem and its dependencies
bundle update gemname
Update everthing
bundle update
GIT
git config --global color.ui true git config --global user.name "Alfredo" git config --global user.email "alfredo.roca.mas@gmail.com" ssh-keygen -t rsa -C "alfredo.roca.mas@gmail.com"
The next step is to take the newly generated SSH key and add it to your Github account. You want to copy and paste the output of the following command and paste it here.
cat ~/.ssh/id_rsa.pub
Once you've done this, you can check and see if it worked:
ssh -T git@github.com
You should get a message like this:
Hi excid3! You've successfully authenticated, but GitHub does not provide shell access.
Installing PostgreSQL Server locally -- ubuntu
Source: https://help.ubuntu.com/community/PostgreSQL
sudo apt-get install postgresql postgresql-contrib sudo apt-get install pgadmin3 sudo -u postgres psql postgres # \password postgres --> enter password for user postgres sudo -u postgres psql # CREATE EXTENSION adminpack;
Edit pg_hba.conf … Ask pg where the file is…
postgres=# show hba_file; hba_file ------------------------------------- /var/lib/pgsql/9.4/data/pg_hba.conf (1 row)
… change method peer by md5
# Database administrative login by Unix domain socket local all postgres md5
sudo /etc/init.d/postgresql reload
Create new postrges user with password
$ sudo -u postgres psql postgres postgres=# CREATE USER username WITH PASSWORD 'password'; postgres=# GRANT ALL PRIVILEGES ON DATABASE database TO username; postgres=# ALTER ROLE username WITH SUPERUSER CREATEDB;
See also:
http://technobytz.com/install-postgresql-9-3-ubuntu.html
Install postreSQL -- fedora
Postgres en Fedora 20
Date: 28/2/2015
https://wiki.postgresql.org/wiki/YUM_Installation
como root
yum localinstall http://yum.postgresql.org/9.4/fedora/fedora-20-i686/pgdg-fedora94-9.4-1.noarch.rpm (esto no sé para qué es)
yum install postgresql94-server
yum install postgresql94-devel
Alternative - with database initialization:
https://fedoraproject.org/wiki/PostgreSQL:
sudo yum install postgresql94-server postgresql94-contrib sudo /usr/pgsql-9.4/bin/postgresql94-setup initdb
In .bash_profile add
export PGHOST=localhost
to make pg start on system boot:
sudo chkconfig postgresql-9.4 on
Failed to build gem native extension installing postgres
If bundle install and gem install pg -v '0.18.1' raises ERROR: Failed to build gem native extension …. Cannot find pg_config file
gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config
Problem: bundling cloned app:
ERROR: Failed to build gem native extension. checking for pg_config… no No pg_config… trying anyway. If building fails, please try again with –with-pg-config=/path/to/pg_config checking for libpq-fe.h… no Can't find the 'libpq-fe.h header
Solution:
bundle config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config
Start/stop postgres --- fedora
sudo /bin/systmctl start/stop postgresql
Postgres Service control
To control the database service, use:
service postgresql-9.4 <command>
where <command> can be:
start : start the database stop : stop the database restart : stop/start the database; used to read changes to core configuration files reload : reload pg_hba.conf file while keeping database running
sudo service postgresql-9.4 start
Reset password
Edit pg_hba.conf en ubuntu: sudo nano /etc/postgresql/9.3/main/pg_hba.conf en fedora: /var/lib/pgsql/data/pg_hba.conf change or add line …
local all postgres trust sameuser
Restart postgres
/etc/init.d/postgresql-8.3 restart
Full removal of Postgres
sudo apt-get --purge remove postgresql\* sudo apt-get remove pgadmin3 sudo rm -rf /etc/postgresql/ sudo rm -r /etc/postgresql-common/ sudo rm -r /var/lib/postgresql/ sudo userdel -r postgres sudo groupdel postgres
pg_ctl
Source: http://www.postgresql.org/docs/9.1/static/app-pg-ctl.html
/usr/lib/postgresql/9.4/bin/pg_ctl start -D data_directory
/usr/lib/postgresql/9.4/bin/pg_ctl stop
/usr/lib/postgresql/9.4/bin/pg_ctl restart -D data_directory
Query for data directory:
postgres=# SHOW data_directory; => data_directory ------------------------------ /var/lib/postgresql/9.4/main
postgres=# select setting from pg_settings where name = 'data_directory';
Postgres Errors
Error messages:
User not found in pg_hba.conf
psql: FATAL: no pg_hba.conf entry for host "[local]", user "couling", database "main", SSL off
User failed password auth:
psql: FATAL: password authentication failed for user "couling"
Missing unix socket file:
psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Unix socket exists, but server not listening to it.
psql: could not connect to server: Connection refused Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Bad file permissions on unix socket file:
psql: could not connect to server: Permission denied Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Environment vars
$ export KEY=value > ENV["KEY"] => "value"
Production env vars
RAILS_ENV=production
RAKE_ENV=production
SECRET_KEY_BASE= (see below)
APP_DATABASE_PASSWORD=
bundle exec rake db:version
Carrierwave in production:
config.serve_static_assets = true
Start rails server
APP_DATABASE_PASSWORD=password rails s -b 127.0.0.1 -p 3000
production secret_key_base generation
$ RAILS_ENV=production rake secret > clave.txt
In one of these files…
$ vi ~/.bash_profile $ vi ~/.bash_login $ vi ~/.profile
… add at the end opening the file clave.txt (in vi :r)
export SECRET_KEY_BASE=clave
Restart console to check:
$ echo $SECRET_KEY_BASE
Bower
npm install -g bower
bash file to start rails server
File name: start_activity_logger.sh
Execute with: ./start_activity_logger.sh
#!/bin/bash --login cd ~/projects/activity_logger/ rvm gemset use activity_logger rails s -p 3001
To execute on boot, put it in /etc/init.d and there execute:
sudo update-rc.d startactivitylogger.sh defaults