Redis service

If you build Redis from source and install it manually, by default it is installed to /usr/local/bin, which is typically included in your system’s PATH. This means you should be able to start it from anywhere using commands like redis-server and redis-cli.

However, there are a few things to consider:

1. Verifying Installation

After running sudo make install, check if the Redis binaries are in your PATH:

which redis-server
which redis-cli

You should see output like:

/usr/local/bin/redis-server
/usr/local/bin/redis-cli

2. Adding Redis to Systemd

To start Redis using systemctl (like a regular service), you need to create a systemd service file. Here’s how:

Step 1: Create a Systemd Service File

sudo nano /etc/systemd/system/redis.service

Add the following content:

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
ExecStart=/usr/local/bin/redis-server /usr/local/etc/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
User=redis
Group=redis
Restart=always

[Install]
WantedBy=multi-user.target

Step 2: Create a Redis User and Configuration

sudo useradd -r -s /bin/false redis
sudo mkdir /var/lib/redis
sudo chown redis:redis /var/lib/redis
sudo chmod 770 /var/lib/redis

Copy the default configuration file and adjust paths:

sudo cp redis-stable/redis.conf /usr/local/etc/redis.conf
sudo nano /usr/local/etc/redis.conf

Set the dir option in redis.conf:

dir /var/lib/redis

Step 3: Enable and Start Redis

sudo systemctl enable redis
sudo systemctl start redis
sudo systemctl status redis

3. Starting Redis Manually

If you prefer not to set it up as a service, you can manually start Redis:

redis-server /usr/local/etc/redis.conf

Or, to run it in the background (detached mode):

redis-server /usr/local/etc/redis.conf --daemonize yes

4. Adding Redis to PATH (If Not Found)

If redis-server is not found in your PATH, you can add /usr/local/bin to your PATH in your shell configuration file (~/.bashrc, ~/.zshrc, etc.):

export PATH=$PATH:/usr/local/bin

Reload the shell configuration:

source ~/.bashrc

Now you should be able to start Redis from anywhere.

Let me know if you encounter any issues or need further assistance!